home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / macros / latex209 / contrib / custom-bib / xbtxbst.mbs (.txt) < prev   
LaTeX Document  |  1993-10-04  |  95KB  |  2,739 lines

  1. %\iffalse
  2. %/////////////////////////////////////////
  3. %   Generic bibliography style           /
  4. %   Adapted from XBTXBST.DOC             /
  5. %   for use with or without MAKEBST.TEX  /
  6. %/////////////////////////////////////////
  7. % This file is self-documenting: simply LaTeX it!
  8. %% (Here are the specifications of the source file)
  9. %<*selfdoc>
  10. \ifx\undefined\endoptions\def\next{%
  11.    \documentstyle[a4,11pt,doc]{article}%
  12.    \def\skipguard##1>{}\MakePercentIgnore\skipguard}\else\let\next\relax\fi
  13. \next
  14. %</selfdoc>
  15. %% \def\filename{xbtxbst.mbs}
  16. %% \def\filedate{1993 Sept 3}
  17. %% \def\fileversion{1.0}
  18. %  \def\docdate{1993 Sept 3}
  19. %\iffalse
  20. %% NOTICE:
  21. %% This file may be used for non-profit purposes.
  22. %% It may not be distributed in exchange for money, 
  23. %%   other than distribution costs.
  24. %%   
  25. %% The author provides it `as is' and does not guarantee it in any way.
  26. %% Copyright (C) 1993 Patrick W. Daly
  27. %% Max-Planck-Institut f\"ur Aeronomie
  28. %% Postfach 20
  29. %% D-37189 Katlenburg-Lindau
  30. %% Germany
  31. %% E-mail:
  32. %% SPAN--     nsp::linmpi::daly    (note nsp also known as ecd1)
  33. %% Internet-- daly@linmpi.dnet.gwdg.de   
  34. %%-----------------------------------------------------------
  35. %   For use with docstrip to select various style parameters
  36. %   This is derived from XBTXBST.DOC version 1.02 of Nelson H.F.Beebe
  37. %   which in turn is derived from Oren Patashnik's BTXBST.DOC.
  38. %   The original files are meant to be processed with a C Preprocessor.
  39. %   I have modified it to run under Frank Mittelbach's DOCSTRIP 
  40. %   program instead, with or without my MAKEBST interface. (MAKEBST
  41. %   uses information in this file to produce, with interactive menus,
  42. %   a DOCSTRIP batch job). I have also taken over Patashnik's (and Beebe's)
  43. %   comments and LaTeXized them so that this whole thing can produce a
  44. %   doc.sty type description. Just LaTeX this file to get it (you will
  45. %   need doc.sty, however).
  46. %                                              PWD
  47. %% \CharacterTable
  48. %%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
  49. %%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
  50. %%   Digits        \0\1\2\3\4\5\6\7\8\9
  51. %%   Exclamation   \!     Double quote  \"     Hash (number) \#
  52. %%   Dollar        \$     Percent       \%     Ampersand     \&
  53. %%   Acute accent  \'     Left paren    \(     Right paren   \)
  54. %%   Asterisk      \*     Plus          \+     Comma         \,
  55. %%   Minus         \-     Point         \.     Solidus       \/
  56. %%   Colon         \:     Semicolon     \;     Less than     \<
  57. %%   Equals        \=     Greater than  \>     Question mark \?
  58. %%   Commercial at \@     Left bracket  \[     Backslash     \\
  59. %%   Right bracket \]     Circumflex    \^     Underscore    \_
  60. %%   Grave accent  \`     Left brace    \{     Vertical bar  \|
  61. %%   Right brace   \}     Tilde         \~}
  62. % \CodelineIndex
  63. % ^^A\OnlyDescription
  64. % \setcounter{StandardModuleDepth}{1}
  65. % \begin{document}
  66. % \setcounter{IndexColumns}{2}
  67. % \setlength{\IndexMin}{10cm}
  68. % \changes{1.0}{1993 Aug 16}{Initial version}
  69. % \pagestyle{headings}
  70. % \title{\bf Docstrip Version of XBTXBST.DOC}
  71. %    
  72. % \author{Patrick W. Daly\thanks{E-mail: {\tt daly@linmpi.dnet.gwdg.de}}\\
  73. %         Max-Planck-Institut f\"ur Aeronomie\\
  74. %         D--37189 Katlenburg-Lindau, Germany}
  75. %         
  76. % \date{This paper describes file {\tt\lowercase\expandafter{\filename}},\\
  77. %  version \fileversion{} from \filedate{},\\
  78. %  documentation from \docdate.}
  79. % \maketitle
  80. % \MakeShortVerb{\|}
  81. % \parskip=1ex \parindent=0pt
  82. % \newcommand{\btx}{{\sc Bib}\TeX}
  83. % \part{About This File}
  84. % \section{Introduction}
  85. % When I got the idea of using Frank Mittelbach's {\tt docstrip} program to
  86. % make up generic, or master, bibliographic style files for \btx, I took
  87. % the standard {\tt.bst} file {\tt plain} plus {\tt apalike} (also from
  88. % Patashnik) and merged them as my model. I wanted to add various options
  89. % using {\tt docstrip} alternative coding, as explained in the next
  90. % sections. However, in order to find out what bibliographic features were
  91. % being used by others, I copied every {\tt.bst} file I could find in order
  92. % to compare the results. In this way I discovered {\tt xbtxbst.doc}, a
  93. % modified version of {\tt btxbst.doc} that includes ISBN and ISSN
  94. % numbers, as well as a |periodical| type. The {\tt.bst} styles produced
  95. % from it are normally prefixed with |is-| to distinguish them from the 
  96. % original four.
  97. % The original file {\tt btxbst.doc} is
  98. % Patashnik's master file for producing the four standard {\tt.bst} files,
  99. % and it works exactly as I visualized using {\tt docstrip}, but with a
  100. % C-pre\-pro\-cessor. It contains only 6 options. It was no great problem
  101. % to convert the preprocessor commands to {\tt docstrip} equivalents.
  102. % However, what is even more interesting is the extensive comments from
  103. % Patashnik that fill the coding. These are simply {\sc ascii} comments,
  104. % but I decided to try to convert them to \LaTeX{} format in order to
  105. % produce a true internally documented file in the manner of Mittelbach's
  106. % {\tt doc.sty} system. For anyone struggling through \btx{} formatting
  107. % language, this will be a great relief.
  108. % I provide this file is such a manner that when it is \LaTeX{}ed, it only
  109. % produces my introductory text, describing master files and {\tt makebst},
  110. % as well as the menus for running {\tt makebst} and {\tt docstrip}. To
  111. % obtain the whole \btx{} coding, with Patashnik's comments, you must
  112. % remove the line |% \OnlyDescription| near the beginning. Removal is done
  113. % not by adding a \% sign (they have been turned off!) but by physical
  114. % deletion, or better, by adding |^^A|, as |% ^^A\OnlyDescription|. This is 
  115. % a speciality of {\tt doc.sty}, and not of normal \LaTeX.
  116. % \section{About Master Bibliographic Style Files}
  117. % \subsection{The {\tt docstrip} Options}
  118. % This master file is a \btx{} bibliographic style file containing
  119. % alternative coding depending on {\tt docstrip} options. The options are
  120. % selected when {\tt docstrip} is run, either interactively or through a
  121. % batch job. 
  122. % Suppose that one of the options is called {\tt xyz}. Then the following
  123. % alternatives are possible:
  124. % \begin{quote}
  125. % |%<xyz> | \em one line of coding
  126. % \end{quote}
  127. % {\em includes\/} the single line of coding;
  128. % \begin{quote}
  129. % |%<!xyz> | \em one line of coding 
  130. % \end{quote}
  131. % {\em excludes\/} the single line;
  132. % \begin{quote}
  133. % |%<*xyz> | \\
  134. % {\em several lines of coding}\\
  135. % |%</xyz> | 
  136. % \end{quote}
  137. % {\em includes\/} all the bracketted lines;
  138. % \begin{quote}
  139. % |%<*!xyz> | \\
  140. % {\em several lines of coding}\\
  141. % |%</!xyz> | 
  142. % \end{quote}
  143. % {\em excludes\/} all the bracketted lines.
  144. % Options may be logically combined: the symbol \verb!|! is a logical {\sf
  145. % or}, |&| a logical {\sf and}, |!| a logical {\sf not}; parentheses {\tt(}
  146. % and {\tt)} may be used to group options.
  147. % \subsection{The {\tt docstrip} Batch Job}
  148. % In order to generate a true \btx{} style file with selected options from
  149. % this master file, it is necessary to run a {\tt docstrip} batch job.
  150. % Suppose that the master file is named {\tt master.mbs}, and the
  151. % resulting \btx{} style file is to be {\tt silly.bst}, and the batch job
  152. % file itself is called {\tt silly.drv}. To produce this with options, say,
  153. % {\tt xyz} and {\tt abc}, the batch job would look something like:
  154. % \begin{quote}\begin{verbatim}
  155. % \def\batchfile{silly.drv}
  156. % \input docstrip
  157. % \preamble
  158. % This is for Journal of Silly Results
  159. % \endpreamble
  160. % \postamble
  161. % End of customized bst file
  162. % \endpostamble
  163. % \keepsilent
  164. % \generateFile{silly.bst}{f}{\from{master.mbs}{xyz,abc}}
  165. % \end{verbatim}
  166. % \end{quote}
  167. % A preamble is not necessary, although it is advisable to include some
  168. % statement about the application of the bibliographic style. A postamble
  169. % {\em is\/} vital, otherwise the default will add |\endinput| at the end
  170. % of the file, something that \btx{} will not understand. The |\keepsilent|
  171. % is optional and just suppresses {\tt docstrip} output during processing.
  172. % \subsection{The {\tt makebst} Program}
  173. % The program {\tt makebst} simplifies the creation of the batch job file. To
  174. % do that, it needs information on the available options. This information
  175. % must be stored in a special format, either in the master file itself, or
  176. % in a file with the same root name but extension {\tt.opt}. The form of
  177. % this format is described in the documentation on {\tt makebst}.
  178. % In the master file, this information must be enclosed within {\tt docstrip}
  179. % options |%<*options>| \dots |%</options>| and {\em must\/} include an
  180. % |\endoptions| command. It may also include any number of comments. 
  181. % A sample menu in the master file to select one or none of options {\tt
  182. % xyz} {\em or\/} {\tt zyx} would look thus:
  183. % \begin{quote}\begin{verbatim}
  184. % %<*options>
  185. % \mes{Select one of these}
  186. % \optdef{f}{xyz}{Option forword}{to do forward stuff}
  187. % \optdef{r}{zyx}{Option reverse}{to do reverse stuff}
  188. % \optdef{*}{}{None of the above}{}
  189. % \getans
  190. % \endoptions
  191. % %</options>
  192. % %<*!options>
  193. % . . . . . . 
  194. % %</!options>
  195. % \end{verbatim}
  196. % \end{quote}
  197. % An explanation of these commands is to be found in the documentation on 
  198. % {\tt makebst}.
  199. % The menu information may be extracted from the master file by means of
  200. % {\tt docstrip} and stored in a file with extension {\tt.opt}. If this
  201. % file is missing, the program tries to read it from the master file.
  202. % \section{The Options}
  203. % The original file {\tt xbtxbst.doc} contains only 6 options for the
  204. % C-pre\-pro\-cessor, which I have easily changed to 6 corresponding {\tt
  205. % docstrip} options. (By comparison, my own master bibliographic style file
  206. % offers about 30.) 
  207. % These six options are:
  208. % \renewcommand{\descriptionlabel}[1]{\hspace\labelsep \tt #1}
  209. % \begin{description}
  210. % \item[lab-alph] an alphabetic label is produced instead of a running
  211. %    number;
  212. %    
  213. % \item[sorted] the references are listed alphabetically by author(s); if
  214. %    this is option is not given, then they appear in the list in the same
  215. %    order as they are cited in the text;
  216. %    
  217. % \item[name-full] first names of authors and editors are written out
  218. %    (provided they have been given in the entry); if this option is
  219. %    missing, then the first names are initialized;
  220. % \item[atit-lower] words in the titles of non-books (i.e., articles) are
  221. %    converted to lowercase, other than the first word, and any words enclosed
  222. %    in braces; if not given, such titles are reproduced as they are in the
  223. %    entry;
  224. %    
  225. % \item[month-full] the names of months are written out in full; otherwise
  226. %    they are abbreviated;
  227. %    
  228. % \item[jour-full] the names of the pre-defined journals are written out in
  229. %    full; otherwise they are abbreviated.
  230. % \end{description}
  231. % The following table shows the values of these options for the four
  232. % standard bibliographic styles (+ means active, $-$ means not active):
  233. % \DeleteShortVerb{\|}
  234. % \begin{center}
  235. % \begin{tabular}{c|cccc}
  236. % {\em Option} & \tt plain & \tt unsrt & \tt abbrv & \tt alph \\ \hline
  237. % \tt lab-alph &     $-$   &     $-$   &     $-$   &    +      \\
  238. % \tt sorted   &      +    &     $-$   &      +    &    +      \\
  239. % \tt name-full&      +    &      +    &     $-$   &    +      \\
  240. % \tt atit-lower&     +    &      +    &      +    &    +      \\
  241. % \tt month-full&     +    &      +    &     $-$   &    +      \\
  242. % \tt jour-full&      +    &      +    &     $-$   &    +      \\ \hline
  243. % \end{tabular}\end{center}
  244. % \MakeShortVerb{\|}
  245. % \section{The Menu Information}
  246. % Here I describe the options and menu information for this particular
  247. % master file for use with {\tt makebst}.
  248. % All this menu information is nested between {\tt docstrip} guard options
  249. % |%<*options>| \dots\ |%</options>|, and the last command is
  250. % |\endoptions|. The rest of the file is nested between |%<*!options>|
  251. % \dots\ |%</!options>| in order to exclude it if {\tt docstrip} is used to
  252. % extract only the menu information.
  253. % First the menu identifies itself.
  254. %    \begin{macrocode}
  255. %<*options>
  256. \mes{^^JThis is XBTXBST.DOC, hacked to work with DOCSTRIP instead}
  257. \mes{\space\space of with a C Preprocessor}
  258. \mes{\space\space It is the Master File for the (extended) standard BibTeX}
  259. \mes{\space\space styles plain, unsrt, abbrv, and alpha}
  260. \mes{\space\space (Extended means ISBN and ISSN are included as fields)}
  261. %    \end{macrocode}
  262. % Now the inquisition begins. Note that the default answers produce the
  263. % {\tt plain} (more properly the {\tt is-plain}) bibliographic style.
  264. % This illustrates how the menu defaults may be different from the {\tt
  265. % docstrip} ones. The |^^J| forces a new line within the output message.
  266. %    \begin{macrocode}
  267. \mes{^^JSelect your options:^^JStyle of label:}
  268. \optdef{*}{}{Numerical}{for plain, unsrt, abbrv}
  269. \optdef{a}{lab-alph}{Alphabetical}{for alpha}
  270. \getans
  271. \mes{^^JOrdering:}
  272. \optdef{*}{sorted}{Sorted}{for plain, abbrv, alpha}
  273. \optdef{u}{}{Unsorted}{for unsrt}
  274. \getans
  275. \mes{^^JAuthor names:}
  276. \optdef{*}{name-full}{Names fully written}{for plain, unsrt, alpha}
  277. \optdef{a}{}{Names abbreviated}{for abbrv}
  278. \getans
  279. \mes{^^JNon-book titles:}
  280. \optdef{*}{atit-lower}{Converted to l.c.}{for plain, unsrt, abbrv, alpha}
  281. \optdef{u}{}{As in entry}{for none}
  282. \getans
  283. \mes{^^JMonth names:}
  284. \optdef{*}{month-full}{Full}{for plain, unsrt, alpha}
  285. \optdef{a}{}{Abbreviated}{for abbrv}
  286. \getans
  287. \mes{^^JJournal names:}
  288. \optdef{*}{jour-full}{Full}{for plain, unsrt, alpha}
  289. \optdef{a}{}{Abbreviated}{for abbrv}
  290. \getans
  291. \endoptions
  292. %</options>
  293. %    \end{macrocode}
  294. % \StopEventually{\relax
  295. %    \DeleteShortVerb{\|}
  296. %    \end{document}}
  297. % \newpage
  298. % \part{The Bibliographic Coding}
  299. % \begin{sl}
  300. % The remaining text is that found in {\tt xbtxbst.doc}, which is 
  301. % almost the same as that in {\tt btxbst.doc}. I have only modified
  302. % it to work as \LaTeX{} input, adding |\tt| where necessary, and changing
  303. % |"text"| to |``text''|, adding environments, and sectioning commands, 
  304. % and so on.
  305. % The original also contains several ``comment versions'' of the coding.
  306. % These are a simplified copy of the function in question. I have kept
  307. % them, as verbatim text. They are part of the comments themselves, and not
  308. % of the coding.
  309. % For more information about how the \btx{} stack language works, see
  310. % Patashnik's article {\tt btxhak.tex} that should be part of the standard
  311. % \LaTeX{} package.
  312. % The initial copyright and explanatory text has been moved from the
  313. % beginning to here; it is output into every {\tt.bst} file produced.
  314. % \end{sl}
  315. %    \begin{macrocode}
  316. %<*!options>
  317.  %% BibTeX `plain' family
  318.  %%       version 0.99b for BibTeX versions 0.99a or later, LaTeX version 2.09.
  319.  %%       Copyright (C) 1985, all rights reserved.
  320.  %%       Copying of this file is authorized only if either
  321.  %%       (1) you make absolutely no changes to your copy, including name, or
  322.  %%       (2) if you do make changes, you name it something other than
  323.  %%       btxbst.doc, plain.bst, unsrt.bst, alpha.bst, and abbrv.bst.
  324.  %%       This restriction helps ensure that all standard styles are identical.
  325.  %%       The file btxbst.doc has the documentation for this style.
  326. %    \end{macrocode}
  327. % \begin{sl}
  328. % From here on, it is Oren Patashnik's original text. Any other comments that
  329. % I may have will be entered in slanted typeface as here.
  330. % \hbox to \hsize{\hfill PWD}
  331. % \end{sl}
  332. % \section{Background}
  333. %   Entry formatting: Similar to that recommended by Mary-Claire van Leunen
  334. %       in ``A Handbook for Scholars''.  Book-like titles are italicized
  335. %       (emphasized) and non-book titles are converted to sentence
  336. %       capitalization (and not enclosed in quotes).
  337. %       This file outputs a |\newblock| between major blocks of an entry
  338. %       (the name |\newblock| is analogous to the names |\newline| and
  339. %          |\newpage|)
  340. %       so that the user can obtain an ``open'' format, which has a line break
  341. %       before each block and lines after the first are indented within blocks,
  342. %       by giving the optional |\documentstyle| argument |openbib|;
  343. %       the default is the ``closed'' format---blocks runs together.
  344. %   Citation alphabetic label format:
  345. % \begin{quote}
  346. %               |[Knu73]| for single author (or editor or key)\\
  347. %               |[AHU83]| (first letters of last names) for multiple authors
  348. % \end{quote}
  349. %   Citation label numberic format:
  350. % \begin{quote}
  351. %               |[number]|
  352. % \end{quote}
  353. %   Reference list ordering for sorted, alphabetic lables:
  354. % \begin{quote}
  355. %               alphabetical by citation label, then by author(s) or whatever
  356. %               passes for author in the absence of one, then by year,
  357. %               then title.
  358. % \end{quote}
  359. %   Reference list ordering for sorted, numeric lables:
  360. % \begin{quote}
  361. %            alphabetical by author(s) or whatever passes
  362. %            for author in the absence of one, then by year, then title.
  363. % \end{quote}
  364. %   Reference list ordering for unsorted:
  365. % \begin{quote}
  366. %               by the order cited in the text.
  367. % \end{quote}
  368. %   History:
  369. % \begin{list}{}{\labelwidth3cm \labelsep20pt \leftmargin\labelwidth
  370. %   \addtolength{\leftmargin}{\labelsep} \rightmargin0pt}
  371. % \item[12/16/84 (HWT)] Original {\tt plain} version, by Howard Trickey.
  372. % \item[12/23/84 (LL)] Some comments made by Leslie Lamport.
  373. % \item[2/16/85 (OP)] Changes based on LL's comments, Oren Patashnik.
  374. % \item[2/17/85 (HWT)] Template file and other standard styles made.
  375. % \item[3/28/85 (OP)] First release, version 0.98b for \btx{} 0.98f.
  376. % \item[5/09/85 (OP)] Version 0.98c for \btx{} 0.98i:
  377. %                       fixed Theoretical Computer Science macro name;
  378. %                       fixed the {\tt format.vol.num.pages} function.
  379. % \item[1/24/88 (OP)] Version 0.99a for \btx{} 0.99a, main changes:
  380. %                       assignment operator (|:=|) arguments reversed;
  381. %                       the |preamble$| function outputs the database 
  382. %                       |PREAMBLE|;
  383. %                       |entry.max$| and |global.max$| (built-in) variables 
  384. %                       replace
  385. %                       |entry.string.max| and |global.string.max|
  386. %                       functions;
  387. %                       alphabetizing by year then title, not just
  388. %                       title;
  389. %                       many unnecessary ties removed;
  390. %                       |\em| $\Rightarrow$ |\em|;
  391. %                       the {\tt alpha} style uses a superscripted `+' 
  392. %                       instead of a
  393. %                       `*' for unnamed names in constructing the
  394. %                       label;
  395. %                       the {\tt abbrv} style now uses ``Mar.''\ and
  396. %                       ``Sept.'';
  397. %                       the functions |calc.label| and |presort| now look 
  398. %                       at just
  399. %                       the fields they're supposed to;
  400. %                       |BOOKLET|, |MASTERSTHESIS|, |TECHREPORT| use nonbook 
  401. %                       titles;
  402. %                       |INBOOK| and |INCOLLECTION| take an optional type
  403. %                       (e.g.\
  404. %                       type = ``Section''), overriding the default
  405. %                       ``chapter'';
  406. %                       |BOOK|, |INBOOK|, |INCOLLECTION|, and
  407. %                       |PROCEEDINGS| now allow
  408. %                       either volume or number, not just volume;
  409. %                       |INCOLLECTION| now allows an edition and series field;
  410. %                        
  411. %                       |PROCEEDINGS| and |INPROCEEDINGS| now use the address 
  412. %                       field
  413. %                       to tell where a conference was held;
  414. %                       |INPROCEEDINGS| and |PROCEEDINGS| now allow either 
  415. %                       volume
  416. %                       or number, and also a series field;
  417. %                       |MASTERSTHESIS| and |PHDTHESIS| accept types other than
  418. %                       ``Master's thesis'' and ``PhD thesis'';
  419. %                       |UNPUBLISHED| now outputs, in one block, note then date;
  420. %                       
  421. %                       |MANUAL| now prints out the organization in
  422. %                       the first block if the author field is empty;
  423. %                       |MISC| can't be empty---it requires some optional field.
  424. % \item[3/23/88 (OP)] Version 0.99b for \btx{} 0.99c---changed the three
  425. %                       erroneous occurrences of {\tt cite} to |cite$|; this
  426. %                       change didn't affect the four standard styles, so the
  427. %                       0.99a versions of those styles are still current.
  428. % \end{list}
  429. % \section{Preliminaries}
  430. % \subsection{The {\tt ENTRY} declaration}
  431. %   Like Scribe's (according to pages 231-2 of the April '84 edition),
  432. %   but no {\tt fullauthor} or {\tt editors} fields because \btx{} does 
  433. %   name handling.
  434. %   The {\tt annote} field is commented out here because this family doesn't
  435. %   include an annotated bibliography style.  And in addition to the fields
  436. %   listed here, \btx{} has a built-in crossref field, explained later.
  437. %    \begin{macrocode}
  438. ENTRY
  439. %    \end{macrocode}
  440. % Fields:
  441. %    \begin{macrocode}
  442.   { address
  443. %    \end{macrocode}
  444. %           Usually the address of a publisher or other type of organization.
  445. %           Put information in this field only if it helps the reader find the
  446. %           thing---for example you should omit the address of a major
  447. %           publisher entirely.  For a |PROCEEDINGS| or an |INPROCEEDINGS|,
  448. %           however, it's the address of the conference; for those two entry
  449. %           types, include the publisher's or organization's address, if
  450. %           necessary, in the publisher or organization field.
  451. %    \begin{macrocode}
  452. %    annote
  453. %    \end{macrocode}
  454. %           Long annotation---for annotated bibliographies (begins sentence).
  455. %    \begin{macrocode}
  456.     author
  457. %    \end{macrocode}
  458. %           Name(s) of author(s), in \btx{} name format.
  459. %    \begin{macrocode}
  460.     booktitle
  461. %    \end{macrocode}
  462. %           Book title when the thing being referenced isn't the whole book.
  463. %           For book entries, the |title| field should be used instead.
  464. %    \begin{macrocode}
  465.     chapter
  466. %    \end{macrocode}
  467. %           Chapter (or section or whatever) number.
  468. %    \begin{macrocode}
  469.     edition
  470. %    \end{macrocode}
  471. %           Edition of a book---should be an ordinal (e.g., ``Second'').
  472. %    \begin{macrocode}
  473.     editor
  474. %    \end{macrocode}
  475. %           Name(s) of editor(s), in \btx{} name format.
  476. %           If there is also an |author| field, then the |editor| field 
  477. %           should be
  478. %           for the book or collection that the work appears in.
  479. %    \begin{macrocode}
  480.     howpublished
  481. %    \end{macrocode}
  482. %            How something strange has been published (begins sentence).
  483. %    \begin{macrocode}
  484.     institution
  485. %    \end{macrocode}
  486. %           Sponsoring institution of a technical report.
  487. %    \begin{macrocode}
  488.     isbn
  489. %    \end{macrocode}
  490. %           ISBN book number (a 10-digit number with optional
  491. %           embedded spaces or hyphens, where a `digit' is one of
  492. %           0123456789X).
  493. %    \begin{macrocode}
  494.     issn
  495. %    \end{macrocode}
  496. %           ISSN serial publication number (an 8-digit number with optional
  497. %           embedded spaces or hyphens, where a `digit' is one of
  498. %           0123456789X).
  499. %    \begin{macrocode}
  500.     journal
  501. %    \end{macrocode}
  502. %           Journal name (macros are provided for many).
  503. %    \begin{macrocode}
  504.     key
  505. %    \end{macrocode}
  506. %           Alphabetizing, labeling, and cross-referencing key
  507. %           (needed when an entry has no |author| or |editor|).
  508. %    \begin{macrocode}
  509.     month
  510. %    \end{macrocode}
  511. %           Month (macros are provided).
  512. %    \begin{macrocode}
  513.     note
  514. %    \end{macrocode}
  515. %           To help the reader find a reference (begins sentence).
  516. %    \begin{macrocode}
  517.     number
  518. %    \end{macrocode}
  519. %           Number of a journal or technical report, or of a work in a series.
  520. %    \begin{macrocode}
  521.     organization
  522. %    \end{macrocode}
  523. %           Organization sponsoring a conference (or publishing a manual); if
  524. %           the |editor| (or |author|) is empty, and if the organization 
  525. %           produces
  526. %           an awkward label or cross reference, you should put appropriately
  527. %           condensed organization information in the |key| field as well.
  528. %    \begin{macrocode}
  529.     pages
  530. %    \end{macrocode}
  531. %           Page number or numbers (use |--| to separate a range, use |+|
  532. %           to indicate pages following that don't form a simple range).
  533. %    \begin{macrocode}
  534.     publisher
  535. %    \end{macrocode}
  536. %           Publisher name.
  537. %    \begin{macrocode}
  538.     school
  539. %    \end{macrocode}
  540. %           School name (for theses).
  541. %    \begin{macrocode}
  542.     series
  543. %    \end{macrocode}
  544. %           The name of a series or set of books.
  545. %           An individual book will also have it's own title.
  546. %    \begin{macrocode}
  547.     title
  548. %    \end{macrocode}
  549. %           The title of the thing you're referring to.
  550. %    \begin{macrocode}
  551.     type
  552. %    \end{macrocode}
  553. %           Type of a Techreport (e.g., ``Research Note'') to be used instead of
  554. %           the default ``Technical Report''; or, similarly, the type of a
  555. %           thesis; or of a part of a book.
  556. %    \begin{macrocode}
  557.     volume
  558. %    \end{macrocode}
  559. %           The volume number of a journal or multivolume work.
  560. %    \begin{macrocode}
  561.     year
  562. %    \end{macrocode}
  563. %           The year should contain only numerals (technically, it should end
  564. %           with four numerals, after purification; doesn't a begin sentence).
  565. %    \begin{macrocode}
  566. %    \end{macrocode}
  567. % There are no integer entry variables
  568. %    \begin{macrocode}
  569. %    \end{macrocode}
  570. % These string entry variables are used to form the citation label.
  571. % In a storage pinch, |sort.label| can be easily computed on the fly.
  572. %    \begin{macrocode}
  573. %<*lab-alph>
  574. %<sorted>  { label extra.label sort.label }
  575. %    \end{macrocode}
  576. % It doesn't seem like a good idea to use an order-of-citation
  577. % reference list when using alphabetic labels, but when this happens
  578. % we do things a little differently
  579. %    \begin{macrocode}
  580. %<!sorted>  { label }
  581. %</lab-alph>
  582. %<!lab-alph>  { label }
  583. %    \end{macrocode}
  584. % \subsection{Description of the Processing}
  585. % Each entry function starts by calling |output.bibitem|, to write the
  586. % |\bibitem| and its arguments to the {\tt.bbl} file.  Then the various fields
  587. % are formatted and printed by |output| or |output.check|.  Those functions
  588. % handle the writing of separators (commas, periods, |\newblock|'s),
  589. % taking care not to do so when they are passed a null string.
  590. % Finally, |fin.entry| is called to add the final period and finish the
  591. % entry.
  592. % A bibliographic reference is formatted into a number of `blocks':
  593. % in the open format, a block begins on a new line and subsequent
  594. % lines of the block are indented.  A block may contain more than
  595. % one sentence (well, not a grammatical sentence, but something to
  596. % be ended with a sentence ending period).  The entry functions should
  597. % call |new.block| whenever a block other than the first is about to be
  598. % started.  They should call |new.sentence| whenever a new sentence is
  599. % to be started.  The output functions will ensure that if two
  600. % |new.sentence|'s occur without any non-null string being output between
  601. % them then there won't be two periods output.  Similarly for two
  602. % successive |new.block|'s.
  603. % The output routines don't write their argument immediately.
  604. % Instead, by convention, that argument is saved on the stack to be
  605. % output next time (when we'll know what separator needs to come
  606. % after it).  Meanwhile, the output routine has to pop the pending
  607. % output off the stack, append any needed separator, and write it.
  608. % \subsubsection{The Output States}
  609. % To tell which separator is needed, we maintain an |output.state|.
  610. % It will be one of these values:
  611. % \begin{description}
  612. % \item[before.all]              just after the |\bibitem|
  613. % \item[mid.sentence]            in the middle of a sentence: comma needed
  614. %                                       if more sentence is output
  615. % \item[after.sentence]          just after a sentence: period needed
  616. % \item[after.block]             just after a block (and sentence):
  617. %                                       period and |\newblock| needed.
  618. % \end{description}
  619. % Note: These styles don't use |after.sentence|.
  620. % \begin{quote}
  621. % VAR: |output.state| : INTEGER \qquad -- state variable for output
  622. % \end{quote}
  623. % \subsubsection{The Output Functions}
  624. % The |output.nonnull| function saves its argument (assumed to be nonnull)
  625. % on the stack, and writes the old saved value followed by any needed
  626. % separator.  The ordering of the tests is decreasing frequency of
  627. % occurrence.
  628. % \begin{verbatim}
  629. % output.nonnull(s) ==
  630. %  BEGIN
  631. %       s := argument on stack
  632. %       if output.state = mid.sentence then
  633. %           write$(pop() * ", ")
  634. %                 -- "pop" isn't a function: just use stack top
  635. %       else
  636. %           if output.state = after.block then
  637. %               write$(add.period$(pop()))
  638. %               newline$
  639. %               write$("\newblock ")
  640. %           else
  641. %               if output.state = before.all then
  642. %                   write$(pop())
  643. %               else        -- output.state should be after.sentence
  644. %                   write$(add.period$(pop()) * " ")
  645. %               fi
  646. %           fi
  647. %           output.state := mid.sentence
  648. %       fi
  649. %       push s on stack
  650. %  END
  651. % \end{verbatim}
  652. % The output function calls |output.nonnull| if its argument is non-empty;
  653. % its argument may be a missing field (thus, not necessarily a string)
  654. % \begin{verbatim}
  655. % output(s) ==
  656. %  BEGIN
  657. %       if not empty$(s) then output.nonnull(s)
  658. %       fi
  659. %  END
  660. % \end{verbatim}
  661. % The |output.check| function is the same as the |output| function except 
  662. % that, if
  663. % necessary, |output.check| warns the user that the |t| field shouldn't be 
  664. % empty
  665. % (this is because it probably won't be a good reference without the field;
  666. % the entry functions try to make the formatting look reasonable even when
  667. % such fields are empty).
  668. % \begin{verbatim}
  669. % output.check(s,t) ==
  670. %  BEGIN
  671. %       if empty$(s) then
  672. %           warning$("empty " * t * " in " * cite$)
  673. %       else output.nonnull(s)
  674. %       fi
  675. %  END
  676. % \end{verbatim}
  677. % The |output.bibitem| function writes the |\bibitem| for the current entry
  678. % (the label should already have been set up), and sets up the separator
  679. % state for the output functions.  And, it leaves a string on the stack
  680. % as per the output convention.
  681. % \begin{verbatim}
  682. % output.bibitem ==
  683. %  BEGIN
  684. %       newline$
  685. %       write$("\bibitem[")     % for alphabetic labels,
  686. %       write$(label)           % these three lines
  687. %       write$("]{")            % are used
  688. %       write$("\bibitem{")             % this line for numeric labels
  689. %       write$(cite$)
  690. %       write$("}")
  691. %       push "" on stack
  692. %       output.state := before.all
  693. %  END
  694. % \end{verbatim}
  695. % The |fin.entry| function finishes off an entry by adding a period to the
  696. % string remaining on the stack.  If the state is still |before.all|
  697. % then nothing was produced for this entry, so the result will look bad,
  698. % but the user deserves it. (We don't omit the whole entry because the
  699. % entry was cited, and a |\bibitem| is needed to define the citation label.)
  700. % \begin{verbatim}
  701. % fin.entry ==
  702. %  BEGIN
  703. %       write$(add.period$(pop()))
  704. %       newline$
  705. %  END
  706. % \end{verbatim}
  707. % The |new.block| function prepares for a new block to be output, and
  708. % |new.sentence| prepares for a new sentence.
  709. % \begin{verbatim}
  710. % new.block ==
  711. %  BEGIN
  712. %       if output.state <> before.all then
  713. %           output.state := after.block
  714. %       fi
  715. %  END
  716. % new.sentence ==
  717. %  BEGIN
  718. %       if output.state <> after.block then
  719. %           if output.state <> before.all then
  720. %               output.state :=  after.sentence
  721. %           fi
  722. %       fi
  723. %  END
  724. % \end{verbatim}
  725. % \subsection{Coding of Output Functions}
  726. %    \begin{macrocode}
  727. INTEGERS { output.state before.all mid.sentence after.sentence after.block }
  728. FUNCTION {init.state.consts}
  729. { #0 'before.all :=
  730.   #1 'mid.sentence :=
  731.   #2 'after.sentence :=
  732.   #3 'after.block :=
  733. %    \end{macrocode}
  734. % The variables |s| and |t| are temporary string holders.
  735. %    \begin{macrocode}
  736. STRINGS { s t }
  737. FUNCTION {output.nonnull}
  738. { 's :=
  739.   output.state mid.sentence =
  740.     { ", " * write$ }
  741.     { output.state after.block =
  742.         { add.period$ write$
  743.           newline$
  744.           "\newblock " write$
  745.         }
  746.         { output.state before.all =
  747.             'write$
  748.             { add.period$ " " * write$ }
  749.           if$
  750.         }
  751.       if$
  752.       mid.sentence 'output.state :=
  753.     }
  754.   if$
  755. FUNCTION {output}
  756. { duplicate$ empty$
  757.     'pop$
  758.     'output.nonnull
  759.   if$
  760. FUNCTION {output.check}
  761. { 't :=
  762.   duplicate$ empty$
  763.     { pop$ "empty " t * " in " * cite$ * warning$ }
  764.     'output.nonnull
  765.   if$
  766. FUNCTION {output.bibitem}
  767. { newline$
  768. %<*lab-alph>
  769.   "\bibitem[" write$
  770.   label write$
  771.   "]{" write$
  772. %</lab-alph>
  773. %<*!lab-alph>
  774.   "\bibitem{" write$
  775. %</!lab-alph>
  776.   cite$ write$
  777.   "}" write$
  778.   newline$
  779.   before.all 'output.state :=
  780. %    \end{macrocode}
  781. % This function finishes all entries.
  782. %    \begin{macrocode}
  783. FUNCTION {fin.entry}
  784. { add.period$
  785.   write$
  786.   newline$
  787. FUNCTION {new.block}
  788. { output.state before.all =
  789.     'skip$
  790.     { after.block 'output.state := }
  791.   if$
  792. FUNCTION {new.sentence}
  793. { output.state after.block =
  794.     'skip$
  795.     { output.state before.all =
  796.         'skip$
  797.         { after.sentence 'output.state := }
  798.       if$
  799.     }
  800.   if$
  801. %    \end{macrocode}
  802. % \subsection{Some Auxiliary Functions}
  803. % These three functions pop one or two (integer) arguments from the stack
  804. % and push a single one, either |0| or |1|.
  805. % The |skip$| in the |and| and |or| functions are used because
  806. % the corresponding |if$| would be idempotent.
  807. %    \begin{macrocode}
  808. FUNCTION {not}
  809. {   { #0 }
  810.     { #1 }
  811.   if$
  812. FUNCTION {and}
  813. {   'skip$
  814.     { pop$ #0 }
  815.   if$
  816. FUNCTION {or}
  817. {   { pop$ #1 }
  818.     'skip$
  819.   if$
  820. %    \end{macrocode}
  821. % Sometimes we begin a new block only if the block will be big enough.  The
  822. % |new.block.checka| function issues a |new.block| if its argument is nonempty;
  823. % |new.block.checkb| does the same if either of its {\em two\/} arguments is 
  824. % nonempty.
  825. %    \begin{macrocode}
  826. FUNCTION {new.block.checka}
  827. { empty$
  828.     'skip$
  829.     'new.block
  830.   if$
  831. FUNCTION {new.block.checkb}
  832. { empty$
  833.   swap$ empty$
  834.   and
  835.     'skip$
  836.     'new.block
  837.   if$
  838. %    \end{macrocode}
  839. % The |new.sentence.check| functions are analogous.
  840. %    \begin{macrocode}
  841. FUNCTION {new.sentence.checka}
  842. { empty$
  843.     'skip$
  844.     'new.sentence
  845.   if$
  846. FUNCTION {new.sentence.checkb}
  847. { empty$
  848.   swap$ empty$
  849.   and
  850.     'skip$
  851.     'new.sentence
  852.   if$
  853. %    \end{macrocode}
  854. % \section{Formatting Functions}
  855. % \subsection{Formatting Names}
  856. % Here are some functions for formatting chunks of an entry.
  857. % By convention they either produce a string that can be followed by
  858. % a comma or period (using |add.period$|, so it is OK to end in a period),
  859. % or they produce the null string.
  860. % A useful utility is the |field.or.null| function, which checks if the
  861. % argument is the result of pushing a `missing' field (one for which no
  862. % assignment was made when the current entry was read in from the database)
  863. % or the result of pushing a string having no non-white-space characters.
  864. % It returns the null string if so, otherwise it returns the field string.
  865. % Its main (but not only) purpose is to guarantee that what's left on the
  866. % stack is a string rather than a missing field.
  867. % \begin{verbatim}
  868. % field.or.null(s) ==
  869. %  BEGIN
  870. %       if empty$(s) then return ""
  871. %       else return s
  872. %  END
  873. % \end{verbatim}
  874. % Another helper function is |emphasize|, which returns the argument emphazised,
  875. % if that is non-empty, otherwise it returns the null string.  Italic
  876. % corrections aren't used, so this function should be used when punctation
  877. % will follow the result.
  878. % \begin{verbatim}
  879. % emphasize(s) ==
  880. %  BEGIN
  881. %       if empty$(s) then return ""
  882. %       else return "{\em " * s * "}"
  883. % \end{verbatim}
  884. % The |format.names| function formats the argument (which should be in
  885. % \btx{} name format) into ``First Von Last, Junior'', separated by commas
  886. % and with an ``and'' before the last (but ending with ``et~al.'' if the last
  887. % of multiple authors is ``others'').  This function's argument should always
  888. % contain at least one name.
  889. % \begin{quote}
  890. % VAR: |nameptr, namesleft, numnames|: INTEGER\\
  891. % pseudoVAR: |nameresult|: STRING \qquad(it's what's accumulated on the stack)
  892. % \end{quote}
  893. % \begin{verbatim}
  894. % format.names(s) ==
  895. %  BEGIN
  896. %       nameptr := 1
  897. %       numnames := num.names$(s)
  898. %       namesleft := numnames
  899. %       while namesleft > 0
  900. %         do
  901. %                               % for full names:
  902. %           t := format.name$(s, nameptr, "{ff~}{vv~}{ll}{, jj}")
  903. %                               % for abbreviated first names:
  904. %           t := format.name$(s, nameptr, "{f.~}{vv~}{ll}{, jj}")
  905. %           if nameptr > 1 then
  906. %               if namesleft > 1 then nameresult := nameresult * ", " * t
  907. %               else if numnames > 2
  908. %                      then nameresult := nameresult * ","
  909. %                    fi
  910. %                    if t = "others"
  911. %                      then nameresult := nameresult * " et~al."
  912. %                      else nameresult := nameresult * " and " * t
  913. %                    fi
  914. %               fi
  915. %           else nameresult := t
  916. %           fi
  917. %           nameptr := nameptr + 1
  918. %           namesleft := namesleft - 1
  919. %         od
  920. %       return nameresult
  921. %  END
  922. % \end{verbatim}
  923. % The |format.authors| function returns the result of
  924. %  |format.names(author)|
  925. % if the |author| is present, or else it returns the null string.
  926. % \begin{verbatim}
  927. % format.authors ==
  928. %  BEGIN
  929. %       if empty$(author) then return ""
  930. %       else return format.names(author)
  931. %       fi
  932. %  END
  933. % \end{verbatim}
  934. % |Format.editors| is like |format.authors|, but it uses the |editor| field,
  935. % and appends ``, editor'' or ``, editors''.
  936. % \begin{verbatim}
  937. % format.editors ==
  938. %  BEGIN
  939. %       if empty$(editor) then return ""
  940. %       else
  941. %           if num.names$(editor) > 1 then
  942. %               return format.names(editor) * ", editors"
  943. %           else
  944. %               return format.names(editor) * ", editor"
  945. %           fi
  946. %       fi
  947. %  END
  948. % \end{verbatim}
  949. % Other formatting functions are similar, so no ``comment version'' will be
  950. % given for them.
  951. % \subsection{Coding the Names Format Functions}
  952. % The |pop$| in this function gets rid of the duplicate `empty' value and
  953. % the |skip$| returns the duplicate field value.
  954. %    \begin{macrocode}
  955. FUNCTION {field.or.null}
  956. { duplicate$ empty$
  957.     { pop$ "" }
  958.     'skip$
  959.   if$
  960. FUNCTION {emphasize}
  961. { duplicate$ empty$
  962.     { pop$ "" }
  963.     { "{\em " swap$ * "}" * }
  964.   if$
  965. INTEGERS { nameptr namesleft numnames }
  966. FUNCTION {format.names}
  967. { 's :=
  968.   #1 'nameptr :=
  969.   s num.names$ 'numnames :=
  970.   numnames 'namesleft :=
  971.     { namesleft #0 > }
  972. %<name-full>    { s nameptr "{ff~}{vv~}{ll}{, jj}" format.name$ 't :=
  973. %<!name-full>    { s nameptr "{f.~}{vv~}{ll}{, jj}" format.name$ 't :=
  974.       nameptr #1 >
  975.         { namesleft #1 >
  976.             { ", " * t * }
  977.             { numnames #2 >
  978.                 { "," * }
  979.                 'skip$
  980.               if$
  981.               t "others" =
  982.                 { " et~al." * }
  983.                 { " and " * t * }
  984.               if$
  985.             }
  986.           if$
  987.         }
  988.         't
  989.       if$
  990.       nameptr #1 + 'nameptr :=
  991.       namesleft #1 - 'namesleft :=
  992.     }
  993.   while$
  994. FUNCTION {format.authors}
  995. { author empty$
  996.     { "" }
  997.     { author format.names }
  998.   if$
  999. FUNCTION {format.editors}
  1000. { editor empty$
  1001.     { "" }
  1002.     { editor format.names
  1003.       editor num.names$ #1 >
  1004.         { ", editors" * }
  1005.         { ", editor" * }
  1006.       if$
  1007.     }
  1008.   if$
  1009. FUNCTION {format.isbn}
  1010. { isbn empty$
  1011.     { "" }
  1012.     { new.block "ISBN " isbn * }
  1013.   if$
  1014. FUNCTION {format.issn}
  1015. { issn empty$
  1016.     { "" }
  1017.     { new.block "ISSN " issn * }
  1018.   if$
  1019. %    \end{macrocode}
  1020. % \subsection{Title and Date Format Functions}
  1021. % The |format.title| function is used for non-book-like titles.
  1022. % For most styles we convert to lowercase (except for the very first letter,
  1023. % and except for the first one after a colon (followed by whitespace)),
  1024. % and hope the user has brace-surrounded words that need to stay capitalized;
  1025. % for some styles, however, we leave it as it is in the database.
  1026. %    \begin{macrocode}
  1027. FUNCTION {format.title}
  1028. { title empty$
  1029.     { "" }
  1030. %<atit-lower>    { title "t" change.case$ }
  1031. %<!atit-lower>    'title
  1032.   if$
  1033. %    \end{macrocode}
  1034. % By default, \btx{} sets the global integer variable |global.max$| 
  1035. % to the \btx{}
  1036. % constant |glob_str_size|, the maximum length of a global string variable.
  1037. % Analogously, \btx{} sets the global integer variable |entry.max$| to
  1038. % |ent_str_size|, the maximum length of an entry string variable.
  1039. % The style designer may change these if necessary (but this is
  1040. % unlikely).
  1041. % The |n.dashify| function makes each single {\tt-} in a string a double
  1042. % {\tt--} if it's not already.
  1043. % \begin{quote}
  1044. % pseudoVAR: |pageresult|: STRING \qquad (it's what's accumulated on the stack)
  1045. % \end{quote}
  1046. % \begin{verbatim}
  1047. % n.dashify(s) ==
  1048. %  BEGIN
  1049. %       t := s
  1050. %       pageresult := ""
  1051. %       while (not empty$(t))
  1052. %         do
  1053. %           if (first character of t = "-")
  1054. %             then
  1055. %               if (next character isn't)
  1056. %                 then
  1057. %                   pageresult := pageresult * "--"
  1058. %                   t := t with the "-" removed
  1059. %                 else
  1060. %                   while (first character of t = "-")
  1061. %                     do
  1062. %                       pageresult := pageresult * "-"
  1063. %                       t := t with the "-" removed
  1064. %                     od
  1065. %               fi
  1066. %             else
  1067. %               pageresult := pageresult * the first character
  1068. %               t := t with the first character removed
  1069. %           fi
  1070. %         od
  1071. %       return pageresult
  1072. %  END
  1073. % \end{verbatim}
  1074. %    \begin{macrocode}
  1075. FUNCTION {n.dashify}
  1076. { 't :=
  1077.     { t empty$ not }
  1078.     { t #1 #1 substring$ "-" =
  1079.         { t #1 #2 substring$ "--" = not
  1080.             { "--" *
  1081.               t #2 global.max$ substring$ 't :=
  1082.             }
  1083.             {   { t #1 #1 substring$ "-" = }
  1084.                 { "-" *
  1085.                   t #2 global.max$ substring$ 't :=
  1086.                 }
  1087.               while$
  1088.             }
  1089.           if$
  1090.         }
  1091.         { t #1 #1 substring$ *
  1092.           t #2 global.max$ substring$ 't :=
  1093.         }
  1094.       if$
  1095.     }
  1096.   while$
  1097. %    \end{macrocode}
  1098. % The |format.date| function is for the month and year, but we give a warning if
  1099. % there's an empty year but the month is there, and we return the empty string
  1100. % if they're both empty.
  1101. %    \begin{macrocode}
  1102. FUNCTION {format.date}
  1103. { year empty$
  1104.     { month empty$
  1105.         { "" }
  1106.         { "there's a month but no year in " cite$ * warning$
  1107.           month
  1108.         }
  1109.       if$
  1110.     }
  1111.     { month empty$
  1112.         'year
  1113.         { month " " * year * }
  1114.       if$
  1115.     }
  1116.   if$
  1117. %    \end{macrocode}
  1118. % The |format.btitle| is for formatting the |title| field when it is a book-like
  1119. % entry---the style used here keeps it in uppers-and-lowers and emphasizes it.
  1120. %    \begin{macrocode}
  1121. FUNCTION {format.btitle}
  1122. { title emphasize
  1123. %    \end{macrocode}
  1124. % For several functions we'll need to connect two strings with a
  1125. % tie (|~|) if the second one isn't very long (fewer than 3 characters).
  1126. % The |tie.or.space.connect| function does that.  It concatenates the two
  1127. % strings on top of the stack, along with either a tie or space between
  1128. % them, and puts this concatenation back onto the stack:
  1129. % \begin{verbatim}
  1130. % tie.or.space.connect(str1,str2) ==
  1131. %    BEGIN
  1132. %       if text.length$(str2) < 3
  1133. %         then return the concatenation of str1, "~", and str2
  1134. %         else return the concatenation of str1, " ", and str2
  1135. %    END
  1136. % \end{verbatim}
  1137. %    \begin{macrocode}
  1138. FUNCTION {tie.or.space.connect}
  1139. { duplicate$ text.length$ #3 <
  1140.     { "~" }
  1141.     { " " }
  1142.   if$
  1143.   swap$ * *
  1144. %    \end{macrocode}
  1145. % The |either.or.check| function complains if both fields or an either-or pair
  1146. % are nonempty.
  1147. % \begin{verbatim}
  1148. % either.or.check(t,s) ==
  1149. %  BEGIN
  1150. %       if empty$(s) then
  1151. %           warning$(can't use both " * t * " fields in " * cite$)
  1152. %       fi
  1153. %  END
  1154. % \end{verbatim}
  1155. %    \begin{macrocode}
  1156. FUNCTION {either.or.check}
  1157. { empty$
  1158.     'pop$
  1159.     { "can't use both " swap$ * " fields in " * cite$ * warning$ }
  1160.   if$
  1161. %    \end{macrocode}
  1162. % The |format.bvolume| function is for formatting the volume and perhaps
  1163. % series name of a multivolume work.  If both a |volume| and a |series| field
  1164. % are there, we assume the |series| field is the title of the whole multivolume
  1165. % work (the |title| field should be the title of the thing being referred to),
  1166. % and we add an ``of {\em series\/}''.  This function is called in mid-sentence.
  1167. %    \begin{macrocode}
  1168. FUNCTION {format.bvolume}
  1169. { volume empty$
  1170.     { "" }
  1171.     { "volume" volume tie.or.space.connect
  1172.       series empty$
  1173.         'skip$
  1174.         { " of " * series emphasize * }
  1175.       if$
  1176.       "volume and number" number either.or.check
  1177.     }
  1178.   if$
  1179. %    \end{macrocode}
  1180. % \subsection{Formats for Special Fields}
  1181. % The |format.number.series| function is for formatting the series name
  1182. % and perhaps number of a work in a series.  This function is similar to
  1183. % |format.bvolume|, although for this one the |series| must exist (and the
  1184. % |volume| must not exist).  If the |number| field is empty we output either
  1185. % the |series| field unchanged if it exists or else the null string.
  1186. % If both the |number| and |series| fields are there we assume the
  1187. % |series| field
  1188. % gives the name of the whole series (the |title| field should be the title
  1189. % of the work being one referred to), and we add an ``in {\em series\/}''.
  1190. % We capitalize ``Number'' when this function is used at the beginning of 
  1191. % a block.
  1192. %    \begin{macrocode}
  1193. FUNCTION {format.number.series}
  1194. { volume empty$
  1195.     { number empty$
  1196.         { series field.or.null }
  1197.         { output.state mid.sentence =
  1198.             { "number" }
  1199.             { "Number" }
  1200.           if$
  1201.           number tie.or.space.connect
  1202.           series empty$
  1203.             { "there's a number but no series in " cite$ * warning$ }
  1204.             { " in " * series * }
  1205.           if$
  1206.         }
  1207.       if$
  1208.     }
  1209.     { "" }
  1210.   if$
  1211. %    \end{macrocode}
  1212. % The |format.edition| function appends ``edition'' to the edition, if present.
  1213. % We lowercase the edition (it should be something like ``Third''), because
  1214. % this doesn't start a sentence.
  1215. %    \begin{macrocode}
  1216. FUNCTION {format.edition}
  1217. { edition empty$
  1218.     { "" }
  1219.     { output.state mid.sentence =
  1220.         { edition "l" change.case$ " edition" * }
  1221.         { edition "t" change.case$ " edition" * }
  1222.       if$
  1223.     }
  1224.   if$
  1225. %    \end{macrocode}
  1226. % The |format.pages| function is used for formatting a page range in a book
  1227. % (and in rare circumstances, an article).
  1228. % The |multi.page.check| function examines the |pages| field for a 
  1229. % |-| or |,| or |+|
  1230. % so that |format.pages| can use ``page'' instead of ``pages'' if none exists.
  1231. % Note: |global.max$| here means ``take the rest of the string''.
  1232. % \begin{quote}
  1233. % VAR: |multiresult|: INTEGER \qquad (actually, a boolean)
  1234. % \end{quote}
  1235. % \begin{verbatim}
  1236. % multi.page.check(s) ==
  1237. %  BEGIN
  1238. %       t := s
  1239. %       multiresult := false
  1240. %       while ((not multiresult) and (not empty$(t)))
  1241. %         do
  1242. %           if (first character of t = "-" or "," or "+")
  1243. %             then multiresult := true
  1244. %             else t := t with the first character removed
  1245. %           fi
  1246. %         od
  1247. %       return multiresult
  1248. %  END
  1249. % \end{verbatim}
  1250. %    \begin{macrocode}
  1251. INTEGERS { multiresult }
  1252. FUNCTION {multi.page.check}
  1253. { 't :=
  1254.   #0 'multiresult :=
  1255.     { multiresult not
  1256.       t empty$ not
  1257.       and
  1258.     }
  1259.     { t #1 #1 substring$
  1260.       duplicate$ "-" =
  1261.       swap$ duplicate$ "," =
  1262.       swap$ "+" =
  1263.       or or
  1264.         { #1 'multiresult := }
  1265.         { t #2 global.max$ substring$ 't := }
  1266.       if$
  1267.     }
  1268.   while$
  1269.   multiresult
  1270. %    \end{macrocode}
  1271. % This function doesn't begin a sentence so ``pages'' isn't capitalized.
  1272. % Other functions that use this should keep that in mind.
  1273. %    \begin{macrocode}
  1274. FUNCTION {format.pages}
  1275. { pages empty$
  1276.     { "" }
  1277.     { pages multi.page.check
  1278.         { "pages" pages n.dashify tie.or.space.connect }
  1279.         { "page" pages tie.or.space.connect }
  1280.       if$
  1281.     }
  1282.   if$
  1283. %    \end{macrocode}
  1284. % The |format.vol.num.pages| function is for the volume, number, and page range
  1285. % of a journal article.  We use the format:  vol(number):pages, with some
  1286. % variations for empty fields.  This doesn't begin a sentence.
  1287. %    \begin{macrocode}
  1288. FUNCTION {format.vol.num.pages}
  1289. { volume field.or.null
  1290.   number empty$
  1291.     'skip$
  1292.     { "\penalty0 (" number * ")" * *
  1293.       volume empty$
  1294.         { "there's a number but no volume in " cite$ * warning$ }
  1295.         'skip$
  1296.       if$
  1297.     }
  1298.   if$
  1299.   pages empty$
  1300.     'skip$
  1301.     { duplicate$ empty$
  1302.         { pop$ format.pages }
  1303.         { ":\penalty0 " * pages n.dashify * }
  1304.       if$
  1305.     }
  1306.   if$
  1307. %    \end{macrocode}
  1308. % The |format.chapter.pages|, if the |chapter| is present, puts whatever 
  1309. % is in the
  1310. % |type| field (or else ``chapter'' if |type| is empty) in front of a 
  1311. % chapter number.
  1312. % It then appends the pages, if present.  This doesn't begin a sentence.
  1313. %    \begin{macrocode}
  1314. FUNCTION {format.chapter.pages}
  1315. { chapter empty$
  1316.     'format.pages
  1317.     { type empty$
  1318.         { "chapter" }
  1319.         { type "l" change.case$ }
  1320.       if$
  1321.       chapter tie.or.space.connect
  1322.       pages empty$
  1323.         'skip$
  1324.         { ", " * format.pages * }
  1325.       if$
  1326.     }
  1327.   if$
  1328. %    \end{macrocode}
  1329. % The |format.in.ed.booktitle| function is used for starting out a sentence
  1330. % that begins ``In {\em booktitle\/}'', putting an editor before the 
  1331. % title if one exists.
  1332. %    \begin{macrocode}
  1333. FUNCTION {format.in.ed.booktitle}
  1334. { booktitle empty$
  1335.     { "" }
  1336.     { editor empty$
  1337.         { "In " booktitle emphasize * }
  1338.         { "In " format.editors * ", " * booktitle emphasize * }
  1339.       if$
  1340.     }
  1341.   if$
  1342. %    \end{macrocode}
  1343. % The function |empty.misc.check| complains if all six fields are empty, and
  1344. % if there's been no sorting or alphabetic-label complaint.
  1345. %    \begin{macrocode}
  1346. FUNCTION {empty.misc.check}
  1347. { author empty$ title empty$ howpublished empty$
  1348.   month empty$ year empty$ note empty$
  1349.   and and and and and
  1350. %<sorted>  key empty$ not and
  1351. %<!sorted&lab-alph>  key empty$ not and
  1352.     { "all relevant fields are empty in " cite$ * warning$ }
  1353.     'skip$
  1354.   if$
  1355. %    \end{macrocode}
  1356. % The function |format.thesis.type| returns either the (case-changed) 
  1357. % |type| field,
  1358. % if it is defined, or else the default string already on the stack
  1359. % (like ``Master's thesis'' or ``PhD thesis'').
  1360. %    \begin{macrocode}
  1361. FUNCTION {format.thesis.type}
  1362. { type empty$
  1363.     'skip$
  1364.     { pop$
  1365.       type "t" change.case$
  1366.     }
  1367.   if$
  1368. %    \end{macrocode}
  1369. % The function |format.tr.number| makes a string starting with
  1370. % ``Technical Report''
  1371. % (or |type|, if that field is defined), followed by the number if there is one;
  1372. % it returns the starting part (with a case change) even if there is no number.
  1373. % This is used at the beginning of a sentence.
  1374. %    \begin{macrocode}
  1375. FUNCTION {format.tr.number}
  1376. { type empty$
  1377.     { "Technical Report" }
  1378.     'type
  1379.   if$
  1380.   number empty$
  1381.     { "t" change.case$ }
  1382.     { number tie.or.space.connect }
  1383.   if$
  1384. %    \end{macrocode}
  1385. % \subsection{Cross-Reference Format Functions}
  1386. % Now come the cross-referencing functions (these are invoked because
  1387. % one entry in the database file(s) cross-references another, by giving
  1388. % the other entry's database key in a |crossref| field).  This feature
  1389. % allows one or more titled things that are part of a larger titled
  1390. % thing to cross-reference the larger thing.  These styles allow for
  1391. % five posibilities: 
  1392. % \begin{enumerate}
  1393. % \item an |ARTICLE| may cross-reference an |ARTICLE|;
  1394. % \item a |BOOK|, 
  1395. % \item |INBOOK|, or 
  1396. % \item |INCOLLECTION| may cross-reference a |BOOK|; or
  1397. % \item an |INPROCEEDINGS| may cross-reference a |PROCEEDINGS|.
  1398. % \end{enumerate}
  1399. % Each of these is explained in more detail later.
  1400. % An |ARTICLE| entry type may cross reference another |ARTICLE| (this is
  1401. % intended for when an entire journal is devoted to a single topic---but
  1402. % since there is no |JOURNAL| entry type, the journal, too, should be
  1403. % classified as an |ARTICLE| but without the |author| and |title| fields).
  1404. % This will result in two warning messages for the journal's entry
  1405. % if it's included in the reference list, but such is life.
  1406. % \begin{verbatim}
  1407. % format.article.crossref ==
  1408. %  BEGIN
  1409. %       if empty$(key) then
  1410. %           if empty$(journal) then
  1411. %               warning$("need key or journal for " * cite$ *
  1412. %                                               " to crossref " * crossref)
  1413. %               return(" \cite{" * crossref * "}")
  1414. %           else
  1415. %               return("In " * emphasize.correct (journal) *
  1416. %                                               " \cite{" * crossref * "}")
  1417. %               fi
  1418. %       else
  1419. %           return("In " * key * " \cite{" * crossref * "}")
  1420. %       fi
  1421. %  END
  1422. % \end{verbatim}
  1423. % The other cross-referencing functions are similar, so no ``comment
  1424. % version'' will be given for them.
  1425. %    \begin{macrocode}
  1426. FUNCTION {format.article.crossref}
  1427. { key empty$
  1428.     { journal empty$
  1429.         { "need key or journal for " cite$ * " to crossref " * crossref *
  1430.           warning$
  1431.           ""
  1432.         }
  1433.         { "In {\em " journal * "\/}" * }
  1434.       if$
  1435.     }
  1436.     { "In " key * }
  1437.   if$
  1438.   " \cite{" * crossref * "}" *
  1439. %    \end{macrocode}
  1440. % We use just the last names of editors for a cross reference: either
  1441. % ``editor'', or ``editor1 and editor2'', or ``editor1 et~al.'' depending on
  1442. % whether there are one, or two, or more than two editors.
  1443. %    \begin{macrocode}
  1444. FUNCTION {format.crossref.editor}
  1445. { editor #1 "{vv~}{ll}" format.name$
  1446.   editor num.names$ duplicate$
  1447.   #2 >
  1448.     { pop$ " et~al." * }
  1449.     { #2 <
  1450.         'skip$
  1451.         { editor #2 "{ff }{vv }{ll}{ jj}" format.name$ "others" =
  1452.             { " et~al." * }
  1453.             { " and " * editor #2 "{vv~}{ll}" format.name$ * }
  1454.           if$
  1455.         }
  1456.       if$
  1457.     }
  1458.   if$
  1459. %    \end{macrocode}
  1460. % A |BOOK| (or |INBOOK|) entry type (assumed to be for a single volume in a
  1461. % multivolume work) may cross reference another |BOOK| (the entire multivolume).
  1462. % Usually there will be an editor, in which case we use that to construct the
  1463. % cross reference; otherwise we use a nonempty |key| field or else the
  1464. % |series|
  1465. % field (since the series gives the title of the multivolume work).
  1466. %    \begin{macrocode}
  1467. FUNCTION {format.book.crossref}
  1468. { volume empty$
  1469.     { "empty volume in " cite$ * "'s crossref of " * crossref * warning$
  1470.       "In "
  1471.     }
  1472.     { "Volume" volume tie.or.space.connect
  1473.       " of " *
  1474.     }
  1475.   if$
  1476.   editor empty$
  1477.   editor field.or.null author field.or.null =
  1478.     { key empty$
  1479.         { series empty$
  1480.             { "need editor, key, or series for " cite$ * " to crossref " *
  1481.               crossref * warning$
  1482.               "" *
  1483.             }
  1484.             { "{\em " * series * "\/}" * }
  1485.           if$
  1486.         }
  1487.         { key * }
  1488.       if$
  1489.     }
  1490.     { format.crossref.editor * }
  1491.   if$
  1492.   " \cite{" * crossref * "}" *
  1493. %    \end{macrocode}
  1494. % An |INCOLLECTION| entry type may cross reference a |BOOK| (assumed to be the
  1495. % collection), or an |INPROCEEDINGS| may cross reference a |PROCEEDINGS|.
  1496. % Often there will be an editor, in which case we use that to construct
  1497. % the cross reference; otherwise we use a nonempty |key| field or else
  1498. % the |booktitle| field (which gives the cross-referenced work's title).
  1499. %    \begin{macrocode}
  1500. FUNCTION {format.incoll.inproc.crossref}
  1501. { editor empty$
  1502.   editor field.or.null author field.or.null =
  1503.     { key empty$
  1504.         { booktitle empty$
  1505.             { "need editor, key, or booktitle for " cite$ * " to crossref " *
  1506.               crossref * warning$
  1507.               ""
  1508.             }
  1509.             { "In {\em " booktitle * "\/}" * }
  1510.           if$
  1511.         }
  1512.         { "In " key * }
  1513.       if$
  1514.     }
  1515.     { "In " format.crossref.editor * }
  1516.   if$
  1517.   " \cite{" * crossref * "}" *
  1518. %    \end{macrocode}
  1519. % \section{The Entry Type Functions}
  1520. % Now we define the type functions for all entry types that may appear
  1521. % in the {\tt.bib} file---e.g., functions like |article| and |book|.  These
  1522. % are the routines that actually generate the {\tt.bbl}-file output for
  1523. % the entry.  These must all precede the |READ| command.  In addition, the
  1524. % style designer should have a function |default.type| for unknown types.
  1525. % Note: The fields (within each list) are listed in order of appearance,
  1526. % except as described for an |inbook| or a |proceedings|.
  1527. % \subsection{The {\tt article} Function}
  1528. % The |article| function is for an article in a journal.  An article may
  1529. % |CROSSREF| another article.
  1530. % \begin{description}
  1531. % \item[] Required fields: |author|, |title|, |journal|, |year|
  1532. % \item[] Optional fields: |volume|, |number|, |pages|, |month|, |note|
  1533. % \end{description}
  1534. % \begin{verbatim}
  1535. % article ==
  1536. %  BEGIN
  1537. %       output.bibitem
  1538. %       output.check(format.authors,"author")
  1539. %       new.block
  1540. %       output.check(format.title,"title")
  1541. %       new.block
  1542. %       if missing$(crossref) then
  1543. %           output.check(emphasize(journal),"journal")
  1544. %           output(format.vol.num.pages)
  1545. %           output.check(format.date,"year")
  1546. %       else
  1547. %           output.nonnull(format.article.crossref)
  1548. %           output(format.pages)
  1549. %       fi
  1550. %       new.block
  1551. %       output(note)
  1552. %       fin.entry
  1553. %  END
  1554. % \end{verbatim}
  1555. % \subsection{The {\tt book} Function}
  1556. % The |book| function is for a whole book.  A book may |CROSSREF| another book.
  1557. % \begin{description}
  1558. % \item[] Required fields: |author| or |editor|, |title|, |publisher|, |year|
  1559. % \item[] Optional fields: |volume| or |number|, |series|, |address|, 
  1560. %          |edition|, |month|, |note|
  1561. % \end{description}
  1562. % \begin{verbatim}
  1563. % book ==
  1564. %  BEGIN
  1565. %       if empty$(author) then output.check(format.editors,"author and editor")
  1566. %       else    output.check(format.authors,"author")
  1567. %               if missing$(crossref) then
  1568. %                   either.or.check("author and editor",editor)
  1569. %               fi
  1570. %       fi
  1571. %       new.block
  1572. %       output.check(format.btitle,"title")
  1573. %       if missing$(crossref) then
  1574. %           output(format.bvolume)
  1575. %           new.block
  1576. %           output(format.number.series)
  1577. %           new.sentence
  1578. %           output.check(publisher,"publisher")
  1579. %           output(address)
  1580. %       else
  1581. %           new.block
  1582. %           output.nonnull(format.book.crossref)
  1583. %       fi
  1584. %       output(format.edition)
  1585. %       output.check(format.date,"year")
  1586. %       new.block
  1587. %       output(note)
  1588. %       fin.entry
  1589. %  END
  1590. % \end{verbatim}
  1591. % The other entry functions are all quite similar, so no ``comment
  1592. %  version'' will be given for them.
  1593. %    \begin{macrocode}
  1594. FUNCTION {article}
  1595. { output.bibitem
  1596.   format.authors "author" output.check
  1597.   new.block
  1598.   format.title "title" output.check
  1599.   new.block
  1600.   crossref missing$
  1601.     { journal emphasize "journal" output.check
  1602.       format.vol.num.pages output
  1603.       format.date "year" output.check
  1604.     }
  1605.     { format.article.crossref output.nonnull
  1606.       format.pages output
  1607.     }
  1608.   if$
  1609.   new.block
  1610.   note output
  1611.   fin.entry
  1612. FUNCTION {book}
  1613. { output.bibitem
  1614.   author empty$
  1615.     { format.editors "author and editor" output.check }
  1616.     { format.authors output.nonnull
  1617.       crossref missing$
  1618.         { "author and editor" editor either.or.check }
  1619.         'skip$
  1620.       if$
  1621.     }
  1622.   if$
  1623.   new.block
  1624.   format.btitle "title" output.check
  1625.   crossref missing$
  1626.     { format.bvolume output
  1627.       new.block
  1628.       format.number.series output
  1629.       new.sentence
  1630.       publisher "publisher" output.check
  1631.       address output
  1632.     }
  1633.     { new.block
  1634.       format.book.crossref output.nonnull
  1635.     }
  1636.   if$
  1637.   format.edition output
  1638.   format.date "year" output.check
  1639.   format.isbn output
  1640.   new.block
  1641.   note output
  1642.   fin.entry
  1643. %    \end{macrocode}
  1644. % \subsection{The {\tt booklet} Function}
  1645. % A booklet is a bound thing without a publisher or sponsoring institution.
  1646. % \begin{description}
  1647. % \item[] Required: |title|
  1648. % \item[] Optional: |author|, |howpublished|, |address|, |month|, |year|,
  1649. %         |note|
  1650. % \end{description}
  1651. %    \begin{macrocode}
  1652. FUNCTION {booklet}
  1653. { output.bibitem
  1654.   format.authors output
  1655.   new.block
  1656.   format.title "title" output.check
  1657.   howpublished address new.block.checkb
  1658.   howpublished output
  1659.   address output
  1660.   format.date output
  1661.   format.isbn output
  1662.   new.block
  1663.   note output
  1664.   fin.entry
  1665. %    \end{macrocode}
  1666. % \subsection{The {\tt inbook} Function}
  1667. % For the conference entry type, see inproceedings.
  1668. % An |inbook| is a piece of a book: either a chapter and/or a page range.
  1669. % It may |CROSSREF| a book.  If there's no |volume| field, the |type| field
  1670. % will come before number and series.
  1671. % \begin{description}
  1672. % \item[] Required: |author| or |editor|, |title|, |chapter| and/or
  1673. %         |pages|, |publisher|, |year|
  1674. % \item[] Optional: |volume| or |number|, |series|, |type|, |address|, 
  1675. % |edition|, |month|, |note|
  1676. % \end{description}
  1677. %    \begin{macrocode}
  1678. FUNCTION {inbook}
  1679. { output.bibitem
  1680.   author empty$
  1681.     { format.editors "author and editor" output.check }
  1682.     { format.authors output.nonnull
  1683.       crossref missing$
  1684.         { "author and editor" editor either.or.check }
  1685.         'skip$
  1686.       if$
  1687.     }
  1688.   if$
  1689.   new.block
  1690.   format.btitle "title" output.check
  1691.   crossref missing$
  1692.     { format.bvolume output
  1693.       format.chapter.pages "chapter and pages" output.check
  1694.       new.block
  1695.       format.number.series output
  1696.       new.sentence
  1697.       publisher "publisher" output.check
  1698.       address output
  1699.     }
  1700.     { format.chapter.pages "chapter and pages" output.check
  1701.       new.block
  1702.       format.book.crossref output.nonnull
  1703.     }
  1704.   if$
  1705.   format.edition output
  1706.   format.date "year" output.check
  1707.   format.isbn output
  1708.   new.block
  1709.   note output
  1710.   fin.entry
  1711. %    \end{macrocode}
  1712. % \subsection{The {\tt incollection} Function}
  1713. % An |incollection| is like |inbook|, but where there is a separate |title|
  1714. % for the referenced thing (and perhaps an |editor| for the whole).
  1715. % An |incollection| may |CROSSREF| a book.
  1716. % \begin{description}
  1717. % \item[] Required: |author|, |title|, |booktitle|, |publisher|, |year|
  1718. % \item[] Optional: |editor|, |volume| or |number|, |series|, |type|, 
  1719. %                   |chapter|, |pages|,
  1720. %                   |address|, |edition|, |month|, |note|
  1721. % \end{description}
  1722. %    \begin{macrocode}
  1723. FUNCTION {incollection}
  1724. { output.bibitem
  1725.   format.authors "author" output.check
  1726.   new.block
  1727.   format.title "title" output.check
  1728.   new.block
  1729.   crossref missing$
  1730.     { format.in.ed.booktitle "booktitle" output.check
  1731.       format.bvolume output
  1732.       format.number.series output
  1733.       format.chapter.pages output
  1734.       new.sentence
  1735.       publisher "publisher" output.check
  1736.       address output
  1737.       format.edition output
  1738.       format.date "year" output.check
  1739.     }
  1740.     { format.incoll.inproc.crossref output.nonnull
  1741.       format.chapter.pages output
  1742.     }
  1743.   if$
  1744.   format.isbn output
  1745.   new.block
  1746.   note output
  1747.   fin.entry
  1748. %    \end{macrocode}
  1749. % \subsection{The {\tt inproceedings} Function}
  1750. % An |inproceedings| is an article in a conference proceedings, and it may
  1751. % |CROSSREF| a proceedings.  If there's no |address| field, the month
  1752. % (and year) will appear just before note.
  1753. % \begin{description}
  1754. % \item[] Required: |author|, |title|, |booktitle|, |year|
  1755. % \item[] Optional: |editor|, |volume| or |number|, |series|, |pages|, 
  1756. %                   |address|, |month|,
  1757. %                   |organization|, |publisher|, |note|
  1758. % \end{description}
  1759. %    \begin{macrocode}
  1760. FUNCTION {inproceedings}
  1761. { output.bibitem
  1762.   format.authors "author" output.check
  1763.   new.block
  1764.   format.title "title" output.check
  1765.   new.block
  1766.   crossref missing$
  1767.     { format.in.ed.booktitle "booktitle" output.check
  1768.       format.bvolume output
  1769.       format.number.series output
  1770.       format.pages output
  1771.       address empty$
  1772.         { organization publisher new.sentence.checkb
  1773.           organization output
  1774.           publisher output
  1775.           format.date "year" output.check
  1776.         }
  1777.         { address output.nonnull
  1778.           format.date "year" output.check
  1779.           new.sentence
  1780.           organization output
  1781.           publisher output
  1782.         }
  1783.       if$
  1784.     }
  1785.     { format.incoll.inproc.crossref output.nonnull
  1786.       format.pages output
  1787.     }
  1788.   if$
  1789.   format.isbn output
  1790.   new.block
  1791.   note output
  1792.   fin.entry
  1793. %    \end{macrocode}
  1794. % The conference function is included for Scribe compatibility.
  1795. %    \begin{macrocode}
  1796. FUNCTION {conference} { inproceedings }
  1797. %    \end{macrocode}
  1798. % \subsection{The {\tt manual} Function}
  1799. % A manual is technical documentation.
  1800. % \begin{description}
  1801. % \item[] Required: |title|
  1802. % \item[] Optional: |author|, |organization|, |address|, |edition|,
  1803. %                   |month|, |year|, |note|
  1804. % \end{description}
  1805. %    \begin{macrocode}
  1806. FUNCTION {manual}
  1807. { output.bibitem
  1808.   author empty$
  1809.     { organization empty$
  1810.         'skip$
  1811.         { organization output.nonnull
  1812.           address output
  1813.         }
  1814.       if$
  1815.     }
  1816.     { format.authors output.nonnull }
  1817.   if$
  1818.   new.block
  1819.   format.btitle "title" output.check
  1820.   author empty$
  1821.     { organization empty$
  1822.         { address new.block.checka
  1823.           address output
  1824.         }
  1825.         'skip$
  1826.       if$
  1827.     }
  1828.     { organization address new.block.checkb
  1829.       organization output
  1830.       address output
  1831.     }
  1832.   if$
  1833.   format.edition output
  1834.   format.date output
  1835.   new.block
  1836.   note output
  1837.   fin.entry
  1838. %    \end{macrocode}
  1839. % \subsection{The {\tt mastersthesis} Function}
  1840. % A |mastersthesis| is a Master's thesis.
  1841. % \begin{description}
  1842. % \item[] Required: |author|, |title|, |school|, |year|
  1843. % \item[] Optional: |type|, |address|, |month|, |note|
  1844. % \end{description}
  1845. %    \begin{macrocode}
  1846. FUNCTION {mastersthesis}
  1847. { output.bibitem
  1848.   format.authors "author" output.check
  1849.   new.block
  1850.   format.title "title" output.check
  1851.   new.block
  1852.   "Master's thesis" format.thesis.type output.nonnull
  1853.   school "school" output.check
  1854.   address output
  1855.   format.date "year" output.check
  1856.   new.block
  1857.   note output
  1858.   fin.entry
  1859. %    \end{macrocode}
  1860. % \subsection{The {\tt misc} Function}
  1861. % A |misc| is something that doesn't fit elsewhere.
  1862. % \begin{description}
  1863. % \item[] Required: at least one of the `optional' fields
  1864. % \item[] Optional: |author|, |title|, |howpublished|, |month|, |year|,
  1865. %                   |note|
  1866. % \end{description}
  1867. %    \begin{macrocode}
  1868. FUNCTION {misc}
  1869. { output.bibitem
  1870.   format.authors output
  1871.   title howpublished new.block.checkb
  1872.   format.title output
  1873.   howpublished new.block.checka
  1874.   howpublished output
  1875.   format.date output
  1876.   format.issn output
  1877.   new.block
  1878.   note output
  1879.   fin.entry
  1880.   empty.misc.check
  1881. %    \end{macrocode}
  1882. % \subsection{The {\tt phdthesis} Function}
  1883. % A phdthesis is like a mastersthesis.
  1884. % \begin{description}
  1885. % \item[] Required: |author|, |title|, |school|, |year|
  1886. % \item[] Optional: |type|, |address|, |month|, |note|
  1887. % \end{description}
  1888. %    \begin{macrocode}
  1889. FUNCTION {phdthesis}
  1890. { output.bibitem
  1891.   format.authors "author" output.check
  1892.   new.block
  1893.   format.btitle "title" output.check
  1894.   new.block
  1895.   "PhD thesis" format.thesis.type output.nonnull
  1896.   school "school" output.check
  1897.   address output
  1898.   format.date "year" output.check
  1899.   new.block
  1900.   note output
  1901.   fin.entry
  1902. %    \end{macrocode}
  1903. % \subsection{The {\tt periodical} Function}
  1904. % {\sl (This is not part of the standard styles, but is an addition in
  1905. %   {\tt xbtxbst.doc}. ---PWD)}
  1906. % A periodical is a publication that appears at regular
  1907. % intervals.  This includes journals, magazines, and newspapers.
  1908. % If there is an |organization| but no |editor| field, the
  1909. % organization will appear as the first optional field (we try to
  1910. % make the first block nonempty); if there's no |address| field,
  1911. % the month (and year) will appear just before note.
  1912. % \begin{description}
  1913. % \item[] Required: |title|, |key|
  1914. % \item[] Optional: |editor|, |volume|, |number|, |series|, |address|,
  1915. %                   |month|, |year|,
  1916. %                   |organization|, |publisher|, |note|, |issn|,
  1917. %                   |howpublished|
  1918. % \end{description}
  1919. %    \begin{macrocode}
  1920. FUNCTION {periodical}
  1921. { output.bibitem
  1922.   editor empty$
  1923.     { organization output }
  1924.     { format.editors output.nonnull }
  1925.   if$
  1926.   new.block
  1927.   title emphasize "title" output.check
  1928. %  format.bvolume output
  1929. %  format.number.series output
  1930.   format.vol.num.pages output
  1931.   format.date output
  1932.   format.issn output
  1933.   new.sentence
  1934.   publisher output
  1935.   address output
  1936.   howpublished new.block.checka
  1937.   howpublished output
  1938.   new.block
  1939.   note output
  1940.   fin.entry
  1941. %    \end{macrocode}
  1942. % \subsection{The {\tt proceedings} Function}
  1943. % A proceedings is a conference proceedings.
  1944. % If there is an |organization| but no |editor| field, the organization will
  1945. % appear as the first optional field (we try to make the first block nonempty);
  1946. % if there's no |address| field, the month (and year) will appear just 
  1947. % before note.
  1948. % \begin{description}
  1949. % \item[] Required: |title|, |year|
  1950. % \item[] Optional: |editor|, |volume| or |number|, |series|, |address|,
  1951. %                   |month|,
  1952. %                   |organization|, |publisher|, |note|
  1953. % \end{description}
  1954. %    \begin{macrocode}
  1955. FUNCTION {proceedings}
  1956. { output.bibitem
  1957.   editor empty$
  1958.     { organization output }
  1959.     { format.editors output.nonnull }
  1960.   if$
  1961.   new.block
  1962.   format.btitle "title" output.check
  1963.   format.bvolume output
  1964.   format.number.series output
  1965.   address empty$
  1966.     { editor empty$
  1967.         { publisher new.sentence.checka }
  1968.         { organization publisher new.sentence.checkb
  1969.           organization output
  1970.         }
  1971.       if$
  1972.       publisher output
  1973.       format.date "year" output.check
  1974.     }
  1975.     { address output.nonnull
  1976.       format.date "year" output.check
  1977.       new.sentence
  1978.       editor empty$
  1979.         'skip$
  1980.         { organization output }
  1981.       if$
  1982.       publisher output
  1983.     }
  1984.   if$
  1985.   format.isbn output
  1986.   new.block
  1987.   note output
  1988.   fin.entry
  1989. %    \end{macrocode}
  1990. % \subsection{The {\tt techreport} Function}
  1991. % A |techreport| is a technical report.
  1992. % \begin{description}
  1993. % \item[] Required: |author|, |title|, |institution|, |year|
  1994. % \item[] Optional: |type|, |number|, |address|, |month|, |note|
  1995. % \end{description}
  1996. %    \begin{macrocode}
  1997. FUNCTION {techreport}
  1998. { output.bibitem
  1999.   format.authors "author" output.check
  2000.   new.block
  2001.   format.title "title" output.check
  2002.   new.block
  2003.   format.tr.number output.nonnull
  2004.   institution "institution" output.check
  2005.   address output
  2006.   format.date "year" output.check
  2007.   new.block
  2008.   note output
  2009.   fin.entry
  2010. %    \end{macrocode}
  2011. % \subsection{The {\tt unpublished} Function}
  2012. % An |unpublished| is something that hasn't been published.
  2013. % \begin{description}
  2014. % \item[] Required: |author|, |title|, |note|
  2015. % \item{} Optional: |month|, |year|
  2016. % \end{description}
  2017. %    \begin{macrocode}
  2018. FUNCTION {unpublished}
  2019. { output.bibitem
  2020.   format.authors "author" output.check
  2021.   new.block
  2022.   format.title "title" output.check
  2023.   new.block
  2024.   note "note" output.check
  2025.   format.date output
  2026.   fin.entry
  2027. %    \end{macrocode}
  2028. % \subsection{The {\tt default.type} Function}
  2029. % We use entry type |misc| for an unknown type; \btx{} gives a warning.
  2030. %    \begin{macrocode}
  2031. FUNCTION {default.type} { misc }
  2032. %    \end{macrocode}
  2033. % \section{Common Features}
  2034. % Here are macros for common things that may vary from style to style.
  2035. % Users are encouraged to use these macros.
  2036. % \subsection{The Months}
  2037. % Months are either written out in full or abbreviated
  2038. %    \begin{macrocode}
  2039. %<*month-full>
  2040. MACRO {jan} {"January"}
  2041. MACRO {feb} {"February"}
  2042. MACRO {mar} {"March"}
  2043. MACRO {apr} {"April"}
  2044. MACRO {may} {"May"}
  2045. MACRO {jun} {"June"}
  2046. MACRO {jul} {"July"}
  2047. MACRO {aug} {"August"}
  2048. MACRO {sep} {"September"}
  2049. MACRO {oct} {"October"}
  2050. MACRO {nov} {"November"}
  2051. MACRO {dec} {"December"}
  2052. %</month-full>
  2053. %<*!month-full>
  2054. MACRO {jan} {"Jan."}
  2055. MACRO {feb} {"Feb."}
  2056. MACRO {mar} {"Mar."}
  2057. MACRO {apr} {"Apr."}
  2058. MACRO {may} {"May"}
  2059. MACRO {jun} {"June"}
  2060. MACRO {jul} {"July"}
  2061. MACRO {aug} {"Aug."}
  2062. MACRO {sep} {"Sept."}
  2063. MACRO {oct} {"Oct."}
  2064. MACRO {nov} {"Nov."}
  2065. MACRO {dec} {"Dec."}
  2066. %</!month-full>
  2067. %    \end{macrocode}
  2068. % \subsection{Journal Names}
  2069. % Journals are either written out in full or abbreviated;
  2070. % the abbreviations are like those found in ACM publications.
  2071. % To get a completely different set of abbreviations, it may be best to make
  2072. % a separate {\tt.bib} file with nothing but those abbreviations; users 
  2073. % could then
  2074. % include that file name as the first argument to the |\bibliography|
  2075. % command.
  2076. %    \begin{macrocode}
  2077. %<*jour-full>
  2078. MACRO {acmcs} {"ACM Computing Surveys"}
  2079. MACRO {acta} {"Acta Informatica"}
  2080. MACRO {cacm} {"Communications of the ACM"}
  2081. MACRO {ibmjrd} {"IBM Journal of Research and Development"}
  2082. MACRO {ibmsj} {"IBM Systems Journal"}
  2083. MACRO {ieeese} {"IEEE Transactions on Software Engineering"}
  2084. MACRO {ieeetc} {"IEEE Transactions on Computers"}
  2085. MACRO {ieeetcad}
  2086.  {"IEEE Transactions on Computer-Aided Design of Integrated Circuits"}
  2087. MACRO {ipl} {"Information Processing Letters"}
  2088. MACRO {jacm} {"Journal of the ACM"}
  2089. MACRO {jcss} {"Journal of Computer and System Sciences"}
  2090. MACRO {scp} {"Science of Computer Programming"}
  2091. MACRO {sicomp} {"SIAM Journal on Computing"}
  2092. MACRO {tocs} {"ACM Transactions on Computer Systems"}
  2093. MACRO {tods} {"ACM Transactions on Database Systems"}
  2094. MACRO {tog} {"ACM Transactions on Graphics"}
  2095. MACRO {toms} {"ACM Transactions on Mathematical Software"}
  2096. MACRO {toois} {"ACM Transactions on Office Information Systems"}
  2097. MACRO {toplas} {"ACM Transactions on Programming Languages and Systems"}
  2098. MACRO {tcs} {"Theoretical Computer Science"}
  2099. %</jour-full>
  2100. %<*!jour-full>
  2101. MACRO {acmcs} {"ACM Comput. Surv."}
  2102. MACRO {acta} {"Acta Inf."}
  2103. MACRO {cacm} {"Commun. ACM"}
  2104. MACRO {ibmjrd} {"IBM J. Res. Dev."}
  2105. MACRO {ibmsj} {"IBM Syst.~J."}
  2106. MACRO {ieeese} {"IEEE Trans. Softw. Eng."}
  2107. MACRO {ieeetc} {"IEEE Trans. Comput."}
  2108. MACRO {ieeetcad}
  2109.  {"IEEE Trans. Comput.-Aided Design Integrated Circuits"}
  2110. MACRO {ipl} {"Inf. Process. Lett."}
  2111. MACRO {jacm} {"J.~ACM"}
  2112. MACRO {jcss} {"J.~Comput. Syst. Sci."}
  2113. MACRO {scp} {"Sci. Comput. Programming"}
  2114. MACRO {sicomp} {"SIAM J. Comput."}
  2115. MACRO {tocs} {"ACM Trans. Comput. Syst."}
  2116. MACRO {tods} {"ACM Trans. Database Syst."}
  2117. MACRO {tog} {"ACM Trans. Gr."}
  2118. MACRO {toms} {"ACM Trans. Math. Softw."}
  2119. MACRO {toois} {"ACM Trans. Office Inf. Syst."}
  2120. MACRO {toplas} {"ACM Trans. Prog. Lang. Syst."}
  2121. MACRO {tcs} {"Theoretical Comput. Sci."}
  2122. %</!jour-full>
  2123. %    \end{macrocode}
  2124. % \section{Processing}
  2125. % \subsection{Input the Entries}
  2126. % Now we read in the {\tt.bib} entries.
  2127. %    \begin{macrocode}
  2128. %    \end{macrocode}
  2129. %\subsection{Auxiliary Functions for Labels}
  2130. % The sortify function converts to lower case after |purify$|ing; it's
  2131. % used in sorting and in computing alphabetic labels after sorting.
  2132. % The |chop.word(w,len,s)| function returns either |s| or, if the first
  2133. % |len|
  2134. % letters of |s| equals |w| (this comparison is done in the third line of the
  2135. % function's definition), it returns that part of |s| after |w|.
  2136. %    \begin{macrocode}
  2137. %<*sorted>
  2138. FUNCTION {sortify}
  2139. { purify$
  2140.   "l" change.case$
  2141. INTEGERS { len }
  2142. FUNCTION {chop.word}
  2143. { 's :=
  2144.   'len :=
  2145.   s #1 len substring$ =
  2146.     { s len #1 + global.max$ substring$ }
  2147.     's
  2148.   if$
  2149. %</sorted>
  2150. %<*lab-alph&!sorted>
  2151. %    \end{macrocode}
  2152. % We need the |chop.word| stuff for the dubious {\em 
  2153. % unsorted-list-with-labels\/} case.
  2154. %    \begin{macrocode}
  2155. INTEGERS { len }
  2156. FUNCTION {chop.word}
  2157. { 's :=
  2158.   'len :=
  2159.   s #1 len substring$ =
  2160.     { s len #1 + global.max$ substring$ }
  2161.     's
  2162.   if$
  2163. %</lab-alph&!sorted>
  2164. %    \end{macrocode}
  2165. % \subsection{Making Labels}
  2166. % This long comment applies only to alphabetic labels.
  2167. % The |format.lab.names| function makes a short label by using the initials of
  2168. % the von and Last parts of the names (but if there are more than four names,
  2169. % (i.e., people) it truncates after three and adds a superscripted |+|;
  2170. % it also adds such a |+| if the last of multiple authors is ``others'').
  2171. % If there is only one name, and its von and Last parts combined have just
  2172. % a single name-token (``Knuth'' has a single token, ``Brinch Hansen'' has two),
  2173. % we take the first three letters of the last name.  The boolean
  2174. % |et.al.char.used| tells whether we've used a superscripted |+|, so that we
  2175. % know whether to include a \LaTeX{} macro for it.
  2176. % \begin{verbatim}
  2177. % format.lab.names(s) ==
  2178. %  BEGIN
  2179. %       numnames := num.names$(s)
  2180. %       if numnames > 1 then
  2181. %           if numnames > 4 then
  2182. %               namesleft := 3
  2183. %           else
  2184. %               namesleft := numnames
  2185. %           nameptr := 1
  2186. %           nameresult := ""
  2187. %           while namesleft > 0
  2188. %             do
  2189. %               if (name_ptr = numnames) and
  2190. %                    format.name$(s, nameptr, "{ff }{vv }{ll}{ jj}") = "others"
  2191. %                  then nameresult := nameresult * "{\etalchar{+}}"
  2192. %                       et.al.char.used := true
  2193. %                  else nameresult := nameresult *
  2194. %                               format.name$(s, nameptr, "{v{}}{l{}}")
  2195. %               nameptr := nameptr + 1
  2196. %               namesleft := namesleft - 1
  2197. %             od
  2198. %           if numnames > 4 then
  2199. %               nameresult := nameresult * "{\etalchar{+}}"
  2200. %               et.al.char.used := true
  2201. %       else
  2202. %           t := format.name$(s, 1, "{v{}}{l{}}")
  2203. %           if text.length$(t) < 2 then % there's just one name-token
  2204. %               nameresult := text.prefix$(format.name$(s,1,"{ll}"),3)
  2205. %           else
  2206. %               nameresult := t
  2207. %           fi
  2208. %       fi
  2209. %       return nameresult
  2210. %  END
  2211. % \end{verbatim}
  2212. % Exactly what fields we look at in constructing the primary part of the label
  2213. % depends on the entry type; this selectivity (as opposed to, say, always
  2214. % looking at author, then editor, then key) helps ensure that ``ignored''
  2215. % fields,
  2216. % as described in the \LaTeX{} book, really are ignored.  Note that
  2217. % |MISC| is part
  2218. % of the deepest `else' clause in the nested part of |calc.label|; thus, any
  2219. % unrecognized entry type in the database is handled correctly.
  2220. % There is one auxiliary function for each of the four different sequences of
  2221. % fields we use.  The first of these functions looks at the |author| field, and
  2222. % then, if necessary, the |key| field.  The other three functions, which might
  2223. % look at two fields and the |key| field, are similar, except that the
  2224. % |key| field
  2225. % takes precedence over the |organization| field (for labels---not for sorting).
  2226. % The |calc.label| function calculates the preliminary label of an entry, which
  2227. % is formed by taking three letters of information from the |author| or 
  2228. % |editor| or
  2229. % |key| or |organization| field (depending on the entry type and on 
  2230. % what's empty,
  2231. % but ignoring a leading ``The '' in the organization), and appending the last
  2232. % two characters (digits) of the year. It is an error if the appropriate fields
  2233. % among |author|, |editor|, |organization|, and |key| are missing, and we use
  2234. % the first three letters of the |cite$| in desperation when this happens.
  2235. % The resulting label has the |year| part, but not the |name| part,
  2236. % |purify$|ed
  2237. % (|purify$|ing the year allows some sorting shenanigans by the user).
  2238. % This function also calculates the version of the label to be used in sorting.
  2239. % The final label may need a trailing `a', `b', etc., to distinguish it from
  2240. % otherwise identical labels, but we can't calculated those
  2241. % |extra.label|s
  2242. % until after sorting.
  2243. % \begin{verbatim}
  2244. % calc.label ==
  2245. %  BEGIN
  2246. %       if type$ = "book" or "inbook" then
  2247. %           author.editor.key.label
  2248. %       else if type$ = "proceedings" then
  2249. %           editor.key.organization.label
  2250. %       else if type$ = "manual" then
  2251. %           author.key.organization.label
  2252. %       else
  2253. %           author.key.label
  2254. %       fi fi fi
  2255. %       label := label * substring$(purify$(field.or.null(year)), -1, 2)
  2256. %               % assuming we will also sort, we calculate a sort.label
  2257. %       sort.label := sortify(label), but use the last four, not two, digits
  2258. %  END
  2259. % \end{verbatim}
  2260. %    \begin{macrocode}
  2261. %<*lab-alph>
  2262. INTEGERS { et.al.char.used }
  2263. FUNCTION {initialize.et.al.char.used}
  2264. { #0 'et.al.char.used :=
  2265. EXECUTE {initialize.et.al.char.used}
  2266. FUNCTION {format.lab.names}
  2267. { 's :=
  2268.   s num.names$ 'numnames :=
  2269.   numnames #1 >
  2270.     { numnames #4 >
  2271.         { #3 'namesleft := }
  2272.         { numnames 'namesleft := }
  2273.       if$
  2274.       #1 'nameptr :=
  2275.       ""
  2276.         { namesleft #0 > }
  2277.         { nameptr numnames =
  2278.             { s nameptr "{ff }{vv }{ll}{ jj}" format.name$ "others" =
  2279.                 { "{\etalchar{+}}" *
  2280.                   #1 'et.al.char.used :=
  2281.                 }
  2282.                 { s nameptr "{v{}}{l{}}" format.name$ * }
  2283.               if$
  2284.             }
  2285.             { s nameptr "{v{}}{l{}}" format.name$ * }
  2286.           if$
  2287.           nameptr #1 + 'nameptr :=
  2288.           namesleft #1 - 'namesleft :=
  2289.         }
  2290.       while$
  2291.       numnames #4 >
  2292.         { "{\etalchar{+}}" *
  2293.           #1 'et.al.char.used :=
  2294.         }
  2295.         'skip$
  2296.       if$
  2297.     }
  2298.     { s #1 "{v{}}{l{}}" format.name$
  2299.       duplicate$ text.length$ #2 <
  2300.         { pop$ s #1 "{ll}" format.name$ #3 text.prefix$ }
  2301.         'skip$
  2302.       if$
  2303.     }
  2304.   if$
  2305. FUNCTION {author.key.label}
  2306. { author empty$
  2307.     { key empty$
  2308. %<sorted>        { cite$ #1 #3 substring$ }
  2309. %<*!sorted>
  2310. %    \end{macrocode}
  2311. % We need a warning here because we won't give it later
  2312. %    \begin{macrocode}
  2313.         { "for label, need author or key in " cite$ * warning$
  2314.           cite$ #1 #3 substring$
  2315.         }
  2316. %</!sorted>
  2317.         { key #3 text.prefix$ }
  2318.       if$
  2319.     }
  2320.     { author format.lab.names }
  2321.   if$
  2322. FUNCTION {author.editor.key.label}
  2323. { author empty$
  2324.     { editor empty$
  2325.         { key empty$
  2326. %<sorted>            { cite$ #1 #3 substring$ }
  2327. %<*!sorted>
  2328.             { "for label, need author, editor, or key in " cite$ * warning$
  2329.               cite$ #1 #3 substring$
  2330.             }
  2331. %</!sorted>
  2332.             { key #3 text.prefix$ }
  2333.           if$
  2334.         }
  2335.         { editor format.lab.names }
  2336.       if$
  2337.     }
  2338.     { author format.lab.names }
  2339.   if$
  2340. FUNCTION {author.key.organization.label}
  2341. { author empty$
  2342.     { key empty$
  2343.         { organization empty$
  2344. %<sorted>            { cite$ #1 #3 substring$ }
  2345. %<*!sorted>
  2346.             { "for label, need author, key, or organization in " cite$ *
  2347.                                                                 warning$
  2348.               cite$ #1 #3 substring$
  2349.             }
  2350. %</!sorted>
  2351.             { "The " #4 organization chop.word #3 text.prefix$ }
  2352.           if$
  2353.         }
  2354.         { key #3 text.prefix$ }
  2355.       if$
  2356.     }
  2357.     { author format.lab.names }
  2358.   if$
  2359. FUNCTION {editor.key.organization.label}
  2360. { editor empty$
  2361.     { key empty$
  2362.         { organization empty$
  2363. %<sorted>            { cite$ #1 #3 substring$ }
  2364. %<*!sorted>
  2365.             { "for label, need editor, key, or organization in " cite$ *
  2366.                                                                 warning$
  2367.               cite$ #1 #3 substring$
  2368.             }
  2369. %</!sorted>
  2370.             { "The " #4 organization chop.word #3 text.prefix$ }
  2371.           if$
  2372.         }
  2373.         { key #3 text.prefix$ }
  2374.       if$
  2375.     }
  2376.     { editor format.lab.names }
  2377.   if$
  2378. FUNCTION {calc.label}
  2379. { type$ "book" =
  2380.   type$ "inbook" =
  2381.     'author.editor.key.label
  2382.     { type$ "proceedings" =
  2383.         'editor.key.organization.label
  2384.         { type$ "manual" =
  2385.             'author.key.organization.label
  2386.             'author.key.label
  2387.           if$
  2388.         }
  2389.       if$
  2390.     }
  2391.   if$
  2392.   duplicate$
  2393.   year field.or.null purify$ #-1 #2 substring$
  2394.   'label :=
  2395.   year field.or.null purify$ #-1 #4 substring$
  2396.   sortify 'sort.label :=
  2397. %    \end{macrocode}
  2398. % \subsection{Sorting}
  2399. % It doesn't seem like a particularly good idea to use an order-of-citation
  2400. % reference list when using alphabetic labels, but we need to have a
  2401. % special pass to calculate labels when this happens.
  2402. %    \begin{macrocode}
  2403. %<!sorted>ITERATE {calc.label}
  2404. %</lab-alph>
  2405. %    \end{macrocode}
  2406. % When sorting, we compute the sortkey by executing |presort| on each entry.
  2407. % The presort key contains a number of |sortify|ed strings, concatenated
  2408. % with multiple blanks between them.  This makes things like ``brinch
  2409. % per''
  2410. % come before ``brinch hansen  per''.
  2411. % The fields used here are: the |sort.label| for alphabetic labels (as set by
  2412. % |calc.label|), followed by the author names (or editor names or organization
  2413. % (with a leading ``The '' removed) or key field, depending on entry type and on
  2414. % what's empty), followed by year, followed by the first bit of the title
  2415. % (chopping off a leading ``The '', ``A '', or ``An '').
  2416. % Names are formatted: Von Last First Junior.
  2417. % The names within a part will be separated by a single blank
  2418. % (such as ``brinch hansen''), two will separate the name parts themselves
  2419. % (except the von and last), three will separate the names,
  2420. % four will separate the names from year (and from label, if alphabetic),
  2421. % and four will separate year from title.
  2422. % The |sort.format.names| function takes an argument that should be in
  2423. % \btx{} name format, and returns a string containing ``\verb*!   !''-separated
  2424. % names in the format described above.  The function is almost the same
  2425. % as |format.names|.
  2426. %    \begin{macrocode}
  2427. %<*sorted>
  2428. FUNCTION {sort.format.names}
  2429. { 's :=
  2430.   #1 'nameptr :=
  2431.   s num.names$ 'numnames :=
  2432.   numnames 'namesleft :=
  2433.     { namesleft #0 > }
  2434.     { nameptr #1 >
  2435.         { "   " * }
  2436.         'skip$
  2437.       if$
  2438. %<name-full>      s nameptr "{vv{ } }{ll{ }}{  ff{ }}{  jj{ }}" format.name$ 't :=
  2439. %<!name-full>      s nameptr "{vv{ } }{ll{ }}{  f{ }}{  jj{ }}" format.name$ 't :=
  2440.       nameptr numnames = t "others" = and
  2441.         { "et al" * }
  2442.         { t sortify * }
  2443.       if$
  2444.       nameptr #1 + 'nameptr :=
  2445.       namesleft #1 - 'namesleft :=
  2446.     }
  2447.   while$
  2448. %    \end{macrocode}
  2449. % The |sort.format.title| function returns the argument,
  2450. % but first any leading ``A ''\,'s, ``An ''\,'s, or ``The ''\,'s are removed.
  2451. % The |chop.word| function uses |s|, so we need another string variable,
  2452. % |t|.
  2453. %    \begin{macrocode}
  2454. FUNCTION {sort.format.title}
  2455. { 't :=
  2456.   "A " #2
  2457.     "An " #3
  2458.       "The " #4 t chop.word
  2459.     chop.word
  2460.   chop.word
  2461.   sortify
  2462.   #1 global.max$ substring$
  2463. %    \end{macrocode}
  2464. % The auxiliary functions here, for the |presort| function, are analogous to
  2465. % the ones for |calc.label|; the same comments apply, except that the
  2466. % |organization| field takes precedence here over the |key| field.  For sorting
  2467. % purposes, we still remove a leading ``The '' from the |organization| field.
  2468. %    \begin{macrocode}
  2469. FUNCTION {author.sort}
  2470. { author empty$
  2471.     { key empty$
  2472.         { "to sort, need author or key in " cite$ * warning$
  2473.           ""
  2474.         }
  2475.         { key sortify }
  2476.       if$
  2477.     }
  2478.     { author sort.format.names }
  2479.   if$
  2480. FUNCTION {author.editor.sort}
  2481. { author empty$
  2482.     { editor empty$
  2483.         { key empty$
  2484.             { "to sort, need author, editor, or key in " cite$ * warning$
  2485.               ""
  2486.             }
  2487.             { key sortify }
  2488.           if$
  2489.         }
  2490.         { editor sort.format.names }
  2491.       if$
  2492.     }
  2493.     { author sort.format.names }
  2494.   if$
  2495. FUNCTION {author.organization.sort}
  2496. { author empty$
  2497.     { organization empty$
  2498.         { key empty$
  2499.             { "to sort, need author, organization, or key in " cite$ * warning$
  2500.               ""
  2501.             }
  2502.             { key sortify }
  2503.           if$
  2504.         }
  2505.         { "The " #4 organization chop.word sortify }
  2506.       if$
  2507.     }
  2508.     { author sort.format.names }
  2509.   if$
  2510. FUNCTION {editor.organization.sort}
  2511. { editor empty$
  2512.     { organization empty$
  2513.         { key empty$
  2514.             { "to sort, need editor, organization, or key in " cite$ * warning$
  2515.               ""
  2516.             }
  2517.             { key sortify }
  2518.           if$
  2519.         }
  2520.         { "The " #4 organization chop.word sortify }
  2521.       if$
  2522.     }
  2523.     { editor sort.format.names }
  2524.   if$
  2525. %    \end{macrocode}
  2526. % There is a limit, |entry.max$|, on the length of an entry string variable
  2527. % (which is what its |sort.key$| is), so we take at most that many characters
  2528. % of the constructed key, and hope there aren't many references that match
  2529. % to that many characters!
  2530. %    \begin{macrocode}
  2531. FUNCTION {presort}
  2532. %<*lab-alph>
  2533. { calc.label
  2534.   sort.label
  2535.   "    "
  2536.   type$ "book" =
  2537. %</lab-alph>
  2538. %<!lab-alph>{ type$ "book" =
  2539.   type$ "inbook" =
  2540.     'author.editor.sort
  2541.     { type$ "proceedings" =
  2542.         'editor.organization.sort
  2543.         { type$ "manual" =
  2544.             'author.organization.sort
  2545.             'author.sort
  2546.           if$
  2547.         }
  2548.       if$
  2549.     }
  2550.   if$
  2551. %<lab-alph> *
  2552.   "    "
  2553.   year field.or.null sortify
  2554.   "    "
  2555.   title field.or.null
  2556.   sort.format.title
  2557.   #1 entry.max$ substring$
  2558.   'sort.key$ :=
  2559. ITERATE {presort}
  2560. %    \end{macrocode}
  2561. % And now we can sort.
  2562. %    \begin{macrocode}
  2563. %</sorted>
  2564. %    \end{macrocode}
  2565. % \subsection{Sorted Alphabetic Labels}
  2566. % This long comment applies only to alphabetic labels, when sorted.
  2567. % Now comes the final computation for alphabetic labels, putting in the `a's
  2568. % and `b's and so forth if required.  This involves two passes: a forward
  2569. % pass to put in the `b's, `c's and so on, and a backwards pass
  2570. % to put in the `a's (we don't want to put in `a's unless we know there
  2571. % are `b's).
  2572. % We have to keep track of the longest (in |width$| terms) label, for use
  2573. % by the |thebibliography| environment.
  2574. % \begin{quote}
  2575. % VAR: |longest.label|, |last.sort.label|, |next.extra|:\quad string \\
  2576. % \quad |longest.label.width|, |last.extra.num|: \quad integer
  2577. % \end{quote}
  2578. % \begin{verbatim}
  2579. % initialize.longest.label ==
  2580. %  BEGIN
  2581. %       longest.label := ""
  2582. %       last.sort.label := int.to.chr$(0)
  2583. %       next.extra := ""
  2584. %       longest.label.width := 0
  2585. %       last.extra.num := 0
  2586. %  END
  2587. % forward.pass ==
  2588. %  BEGIN
  2589. %       if last.sort.label = sort.label then
  2590. %           last.extra.num := last.extra.num + 1
  2591. %           extra.label := int.to.chr$(last.extra.num)
  2592. %       else
  2593. %           last.extra.num := chr.to.int$("a")
  2594. %           extra.label := ""
  2595. %           last.sort.label := sort.label
  2596. %       fi
  2597. %  END
  2598. % reverse.pass ==
  2599. %  BEGIN
  2600. %       if next.extra = "b" then
  2601. %           extra.label := "a"
  2602. %       fi
  2603. %       label := label * extra.label
  2604. %       if width$(label) > longest.label.width then
  2605. %           longest.label := label
  2606. %           longest.label.width := width$(label)
  2607. %       fi
  2608. %       next.extra := extra.label
  2609. %  END
  2610. % \end{verbatim}
  2611. %    \begin{macrocode}
  2612. %<*lab-alph>
  2613. %<*sorted>
  2614. STRINGS { longest.label last.sort.label next.extra }
  2615. INTEGERS { longest.label.width last.extra.num }
  2616. FUNCTION {initialize.longest.label}
  2617. { "" 'longest.label :=
  2618.   #0 int.to.chr$ 'last.sort.label :=
  2619.   "" 'next.extra :=
  2620.   #0 'longest.label.width :=
  2621.   #0 'last.extra.num :=
  2622. FUNCTION {forward.pass}
  2623. { last.sort.label sort.label =
  2624.     { last.extra.num #1 + 'last.extra.num :=
  2625.       last.extra.num int.to.chr$ 'extra.label :=
  2626.     }
  2627.     { "a" chr.to.int$ 'last.extra.num :=
  2628.       "" 'extra.label :=
  2629.       sort.label 'last.sort.label :=
  2630.     }
  2631.   if$
  2632. FUNCTION {reverse.pass}
  2633. { next.extra "b" =
  2634.     { "a" 'extra.label := }
  2635.     'skip$
  2636.   if$
  2637.   label extra.label * 'label :=
  2638.   label width$ longest.label.width >
  2639.     { label 'longest.label :=
  2640.       label width$ 'longest.label.width :=
  2641.     }
  2642.     'skip$
  2643.   if$
  2644.   extra.label 'next.extra :=
  2645. EXECUTE {initialize.longest.label}
  2646. ITERATE {forward.pass}
  2647. REVERSE {reverse.pass}
  2648. %</sorted>
  2649. %<*!sorted>
  2650. %    \end{macrocode}
  2651. % It still doesn't seem like a good idea to use an order-of-citation
  2652. % reference list when using alphabetic labels, but when this happens we
  2653. % must compute the longest label
  2654. %    \begin{macrocode}
  2655. STRINGS { longest.label }
  2656. INTEGERS { longest.label.width }
  2657. FUNCTION {initialize.longest.label}
  2658. { "" 'longest.label :=
  2659.   #0 'longest.label.width :=
  2660. FUNCTION {longest.label.pass}
  2661. { label width$ longest.label.width >
  2662.     { label 'longest.label :=
  2663.       label width$ 'longest.label.width :=
  2664.     }
  2665.     'skip$
  2666.   if$
  2667. EXECUTE {initialize.longest.label}
  2668. ITERATE {longest.label.pass}
  2669. %</!sorted>
  2670. %</lab-alph>
  2671. %<*!lab-alph>
  2672. %    \end{macrocode}
  2673. % \subsection{Numeric Labels}
  2674. % Now comes the computation for numeric labels.
  2675. % We use either the sorted order or original order.
  2676. % We still have to keep track of the longest (in |width$| terms) label, for use
  2677. % by the |thebibliography| environment.
  2678. %    \begin{macrocode}
  2679. STRINGS { longest.label }
  2680. INTEGERS { number.label longest.label.width }
  2681. FUNCTION {initialize.longest.label}
  2682. { "" 'longest.label :=
  2683.   #1 'number.label :=
  2684.   #0 'longest.label.width :=
  2685. FUNCTION {longest.label.pass}
  2686. { number.label int.to.str$ 'label :=
  2687.   number.label #1 + 'number.label :=
  2688.   label width$ longest.label.width >
  2689.     { label 'longest.label :=
  2690.       label width$ 'longest.label.width :=
  2691.     }
  2692.     'skip$
  2693.   if$
  2694. EXECUTE {initialize.longest.label}
  2695. ITERATE {longest.label.pass}
  2696. %</!lab-alph>
  2697. %    \end{macrocode}
  2698. % \subsection{Writing the {\tt.bbl} File}
  2699. % Now we're ready to start writing the {\tt.bbl} file.
  2700. % We begin, if necessary, with a \LaTeX{} macro for unnamed names in an 
  2701. % alphabetic
  2702. % label; next comes stuff from the |preamble| command in the database files.
  2703. % Then we give an incantation containing the command
  2704. % \begin{quote}
  2705. % |    \begin{thebibliography}{...}|
  2706. % \end{quote}
  2707. % where the |...| is the longest label.
  2708. % We also call |init.state.consts|, for use by the output routines.
  2709. %    \begin{macrocode}
  2710. FUNCTION {begin.bib}
  2711. %<*lab-alph>
  2712. { et.al.char.used
  2713.     { "\newcommand{\etalchar}[1]{$^{#1}$}" write$ newline$ }
  2714.     'skip$
  2715.   if$
  2716.   preamble$ empty$
  2717. %</lab-alph>
  2718. %<!lab-alph>{ preamble$ empty$
  2719.     'skip$
  2720.     { preamble$ write$ newline$ }
  2721.   if$
  2722.   "\begin{thebibliography}{"  longest.label  * "}" * write$ newline$
  2723. EXECUTE {begin.bib}
  2724. EXECUTE {init.state.consts}
  2725. %    \end{macrocode}
  2726. % Now we produce the output for all the entries.
  2727. %    \begin{macrocode}
  2728. ITERATE {call.type$}
  2729. %    \end{macrocode}
  2730. % Finally, we finish up by writing the `|\end{thebibliography}|' command.
  2731. %    \begin{macrocode}
  2732. FUNCTION {end.bib}
  2733. { newline$
  2734.   "\end{thebibliography}" write$ newline$
  2735. EXECUTE {end.bib}
  2736. %</!options>
  2737. %    \end{macrocode}
  2738. % \Finale
  2739.